开发者

Enable/Disable other elements based on selection

<select name="feature1">
  <option value="1">Enable</option开发者_如何学JAVA>
  <option value="0">Disable</option>
</select>

<input type="checkbox" name="feature2" />
<input type="checkbox" name="feature3" />

How do I disable 'feature2' and 'featured3' inputs when 'disable' in 'feature1' is selected?

Thanks


This automatically enables the items again when 'Enable' is selected, which I assume is also what you want.

$('select[name=feature1]').change(function() {
   $('input[name=feature2],input[name=feature3]').attr('disabled', $(this).val() == '0');
});


I'm going to assume you have ID's the same as your element names, for simplicity

jQuery('#feature1').change(function() {
   jQuery("#feature2, #feature3").attr("disabled", jQuery(this).val() == '0'); 
});


Add some ids for your elements, then:

$('#feature1').change(function() {
  if(this.value === "0") {
    $('#feature2').attr('disabled', 'disabled');
    $('#feature3').attr('disabled', 'disabled');
  }
});


<script type="text/javascript">
 abc(val){
    if (val.value=="0"){
      document.getElementByID("").disabled= true;
      document.getElementByID("").disabled= true;
    }else{
      document.getElementByID("").disabled= false;
      document.getElementByID("").disabled= false;
    }
  }

</script>

<select name="feature1" onchange="abc(this)">
  <option value="1">Enable</option>
  <option value="0">Disable</option>
</select>

<input type="checkbox" name="feature2" id="feature2" />
<input type="checkbox" name="feature3" id="feature3" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜