开发者

Problem preventing form submit using jquery

I have simple form. I want to use jquery to prevent form submit.

$(document).ready(function() {
    $('#searchform').submit(function(e) {
         alert('Handler for .submit() called.');
         event.preventDefault();
         return false;
   });
});

This works fine in chrome. It just shows me a alert box and does not redirect. But does not work on Firefox or IE9, it shows the alert and then goes ahead with form submission.

I appreciate any he开发者_JS百科lp.


change

 event.preventDefault();

into

 e.preventDefault();


Since you're already returning false, you don't also need any sort of event.preventDefault() call at all.

The reason that neither of these seem to work for you is that event is undefined, so an exception is thrown when calling event.preventDefault(), so the method handler exits prematurely.


event.preventDefault();

should be

e.preventDefault(); 

Try that and see if it fixes the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜