문제

I'd like to prevent PJAX clicking of a link unless an input box is keyed up.

Here's the code:

$('a.pjax').pjax({container: '#main_content'}).live('click', function(event){ 
   if(keyed){ 
        console.log('yes, you typed');
   }
   else if(keyed==false){
        console.log('no, please type something');
        event.preventDefault();                                                 
   }
}); 

My problem is that despite the condition being determined correctly, PJAX still loads the page regardless of the preventDefault().

Any thoughts on why this is not working?

도움이 되었습니까?

해결책

It seems the pjax function will always fire with the set-up you have in place.

However, the following should work:

$(document).on('click', 'a.pjax', function (event) {
    if (keyed) {
        console.log('yes, you typed');
        return $.pjax.click(event, '#main_content');
    }
    else {
        console.log('no, please type something');
        return false;
    }
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top