开发者

Submit event from few forms

开发者 https://www.devze.com 2022-12-26 05:24 出处:网络
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){

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

精彩评论

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