开发者

Submit event from few forms

I have a two or more forms on my page in a row. I'm trying to hook submit event like:

$('form',someObj).submit(function(e){ 
   /* Do some stuff with ajax */ 
   return false; 
});

But always receive events only from a first (by code) form.

Also used each() function to 开发者_StackOverflow中文版bind event for each object, same thing..

What's wrong? Thanks!


If someObj contains both forms this will work, however if you just want to attach to the only two forms in the page, leave the context off the selector, like this:

$('form').submit(function(e){ 
 /* Do some stuff with ajax */ 
 return false; 
});

This will search for all forms in the document, alternatively, search for forms via a class or ID, like this:

$('form.ajaxy') //forms with class="ajaxy"
$('#form1, #form2') //forms with id="form1" and id="form2"
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜