Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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
Javascript 如果未选中复选框,则禁用html中的文本输入,反之亦然,请使用JQUERY_Javascript_Jquery_Html_Checkbox - Fatal编程技术网

Javascript 如果未选中复选框,则禁用html中的文本输入,反之亦然,请使用JQUERY

Javascript 如果未选中复选框,则禁用html中的文本输入,反之亦然,请使用JQUERY,javascript,jquery,html,checkbox,Javascript,Jquery,Html,Checkbox,我有一个具有不同行和列的html表,文本输入有一个类似于复选框值的类 如果未选中复选框,我想禁用与复选框位于同一行的textinput 这是html <table> <tr> <td><input type="checkbox" name="new" value="37"></td> <td><input type="text" name="new" id="quantity" class="37"></t

我有一个具有不同行和列的html表,文本输入有一个类似于复选框值的类

如果未选中复选框,我想禁用与复选框位于同一行的textinput

这是html

<table>
<tr>
<td><input type="checkbox" name="new" value="37"></td>
<td><input type="text" name="new" id="quantity" class="37"></td>
</tr>

 <tr>
<td><input type="checkbox" name="new" value="38"></td>
<td><input type="text" name="new" id="quantity" class="38"></td>
</tr>
  .....#this continue
</table>

……这种情况继续下去
我想检查复选框是否被选中,从而禁用输入

如何继续使用jquery

试试:

$('input[type=checkbox]').each(function(){
  if($(this)){
   $(this).siblings("input[type=text]").prop('disabled', false);
  }
else{
  $(this).siblings("input[type=text]").prop('disabled', true);
}
});
$('input[type=checkbox]').click(function(){
if($(this)){
   $(this).siblings("input[type=text]").prop('disabled', false);
  }
else{
  $(this).siblings("input[type=text]").prop('disabled', true);
}
});
使用此代码:

 $(":checkbox[class=ch]").on("change",function(){

 $("input[class = " + $(this).attr("value") + "]").prop("disabled",!$(this).prop("checked"));

 })
最终代码:


这是测试
$(文档).ready(函数(){
$(“:checkbox[class=ch]”。在(“更改”,函数()上){
$(“输入[class=”+$(this.attr(“value”)+“]”)prop.prop(“禁用”)、!$(this.prop(“选中”));
})
})

只有当您只有一个文本和复选框时,该复选框的可能重复项才能正常工作,否则它会失败。如果您有其他复选框,请将复选框的id包含在code@GEOFFREYMWANGI,使用
class
而不是
Id
。我更新了我的答案。如果有帮助,请标记它。