0

これは私の検証機能です。フォームが 1 つある場合は正常に機能し、1 つのページに複数のフォームがある場合は機能しません。

<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>

最初のフォーム ID を呼び出す方法を教えてください。

4

1 に答える 1

0

You can give both name-fields same class and instead of id you can call element by class. If you call specific form you can validate only that forms name-field:

$("#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>
于 2012-12-01T10:41:19.230 に答える