Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 根据选择启用/禁用其他元素 使可能 使残废_Jquery_Select_Conditional Statements - Fatal编程技术网

Jquery 根据选择启用/禁用其他元素 使可能 使残废

Jquery 根据选择启用/禁用其他元素 使可能 使残废,jquery,select,conditional-statements,Jquery,Select,Conditional Statements,在“功能1”中选择“禁用”时,如何禁用“功能2”和“功能3”输入 谢谢当选择“启用”时,这会自动再次启用项目,我想这也是您想要的 <select name="feature1"> <option value="1">Enable</option> <option value="0">Disable</option> </select> <input type="checkbox" name="feature2

在“功能1”中选择“禁用”时,如何禁用“功能2”和“功能3”输入


谢谢

当选择“启用”时,这会自动再次启用项目,我想这也是您想要的

<select name="feature1">
  <option value="1">Enable</option>
  <option value="0">Disable</option>
</select>

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

为元素添加一些ID,然后:

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

为了简单起见,我假设您的ID与元素名相同

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

abc(val){
如果(值=“0”){
document.getElementByID(“”).disabled=true;
document.getElementByID(“”).disabled=true;
}否则{
document.getElementByID(“”).disabled=false;
document.getElementByID(“”).disabled=false;
}
}
使可能
使残废

很抱歉,我没有看到jquery标记,但我没有删除记录的答案。该值永远不会是
==0
,因为它是一个字符串。此外,一些旧版本没有
this.value
(在当时,您必须编写
this[this.selectedIndex].value
),因此为了兼容性,我建议使用
$(this.val()
或选中
selectedIndex==1
,而不是比较值。而且,它们不是ID,feature3不受影响。我输入了错误的字符串。值比jQuery所能获得的兼容性更强。在您完成评论之前,feature3已经存在了。:)
jQuery('#feature1').change(function() {
   jQuery("#feature2, #feature3").attr("disabled", jQuery(this).val() == '0'); 
});
<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" />