フォームの必須フィールドを検証しており、クラス "standard_input" をクラス "standard_input_error" に置き換えたいのですが、次のコードが機能しません。また、検証が必要な ID ごとに関数を記述する必要がないように、関数を組み合わせることは可能ですか (検証を必要としないテキスト フィールドがいくつかあるため、フォーム全体に使用することはできません)。 . 前もって感謝します。
$('#firstname').blur(function()
{
if( !$(this).val() ) {
$(this).addClass('standard_input_error');
}
});
Firstname * <input type="text" id="firstname" name="firstname" class="standard_input">
Last Name* <input type="text" id="lastname" name="lastname" class="standard_input">
another * <input type="text" id="another" name="another" class="standard_input">
another 2 <input type="text" id="another2" name="another2" class="standard_input">
Field * <input type="text" id="fieldb" name="fieldb" class="standard_input">
Blah blah <input type="text" id="blah" name="blah" class="standard_input">
Checkbox 1* <input type="checkbox" checked="checked" id="cbox1" name="cbox1" />
Blah bla 1 <input type="checkbox" checked="checked" id="blabla" name="blabla" />
Blee blee1* <input type="checkbox" checked="checked" id="blee" name="blee" />
bloblo 1 <input type="checkbox" checked="checked" id="blo" name="blo" />