如果输入字段已完成,则删除类jquery

时间:2013-12-05 15:58:39

标签: jquery input removeclass

尝试从下拉列表中删除验证类,具体取决于之前的字段是否已完成。

这是代码

 $('#NatCode').on('keyup', function () {
     // check if input has something in it
     if ($(this).val() != "") {

         $('#optone, #carNum').addClass('required');
     } else {
         $('#optone, #carNum').removeClass('required');
     }
 });

这里是html的一部分

<div>
          <label for="NatCode" class="label">Eurotax NatCode </label>
          <input name="00N11000000KAoq" type="text" id="NatCode" maxlength="80" size="20" title="Please type your natcode."/>
</div>



<label for="model" class="label model">Marque</label>
<select id="optone" name="00N20000003bgum" size="1" onchange="setOptions(document.signup.optone.options[ document.signup.optone.selectedIndex].value);" title="Please choose a make" class="required">
    <option value="" selected="selected"></option>
    <option value="ABARTH">ABARTH</option>
    <option value="ALFA ROMEO">ALFA ROMEO</option>
    <option value="ASTON MARTIN">ASTON MARTIN</option>
    <option value="AUDI">AUDI</option>
</select>
</div>

<div>
    <label for="" class="label model">model</label>
    <select id="carNum" name="00N20000003bog1" size="1" maxlength="80" class="required">
        <option value="" selected="selected">Model of car</option>
    </select>
</div>

我是jquery的新手,我在这里完全遗漏了什么?

0 个答案:

没有答案