2012-12-01 109 views
0

这是我的验证函数,它在一个表单有多个表单并且单个页面中有多个表单不工作时工作正常。具有单一验证功能的多个表单jquery验证

<script> 
    $(function() { 
     $("form").validity(function() { 
      $("#name").require(); 
     });  
    });  
</script> 

我的形式是像

<form action="#" method="post" id="firstform"> 
<input type="text" id="name"> 
</form> 
<form action="#" method="post" id="secondform"> 
<input type="text" id="name_othername"> 
</form> 

谁能给我点建议,如何调用第一种形式IDS 感谢

回答

0

你可以给这两个名字字段相同的类和替代ID你可以按类来调用元素。如果你调用特定的形式,你只能验证形成名称字段:

$("#firstform").validity(function() { 
    $(this).find(".name_class").require(); 
}); 

<form action="#" method="post" id="firstform"> 
<input type="text" id="name" class="name_class"> 
</form> 
<form action="#" method="post" id="secondform"> 
<input type="text" id="name_othername" class="name_class"> 
</form> 
+0

这是行不通的,我怎么可以叫选择性形式,形成一个或formn 2 –

+0

看到编辑。现在函数完全通过它的id来引用第一个表单。这有帮助吗? –

+0

感谢这对我有用 –