Javascript 选中时启用带循环的文本框
当选中复选框时,如何在循环中启用文本框?。你们能帮我怎么做吗Javascript 选中时启用带循环的文本框,javascript,jquery,Javascript,Jquery,当选中复选框时,如何在循环中启用文本框?。你们能帮我怎么做吗 <table class="table table-bordered table-hover mt-2"> <thead> <tr> <th>Select</th> <th>Duties and Responsibilities</th>
<table class="table table-bordered table-hover mt-2">
<thead>
<tr>
<th>Select</th>
<th>Duties and Responsibilities</th>
<th>Weight of Duties</th>
<th>Rate of Department Head</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
@for (int x = 0; x <= 7; x++)
{
<tr>
<td><input type="checkbox" class="form-control" /></td>
<td><input type="text" name="JdDescription" class="form-control" disabled/></td>
<td><input type="text" readonly name="WeightofDuties" class="form-control" /></td>
<td><input type="text" name="RateofHead" class="form-control" disabled/></td>
<td><input type="text" name="Remarks" class="form-control" disabled/></td>
</tr>
}
</tbody>
</table>
挑选
职责
职责重量
部门负责人比率
评论
@对于(int x=0;x在单击复选框时获取父
元素,然后在此
节点中启用文本输入:
$('input[type=checkbox]').change(function () {
var disabled = this.checked ? '' : 'disabled';
$(this).parents('tr').find('input[type=text]').prop('disabled', disabled);
});
这也将在取消选中复选框后再次禁用输入[type=text]字段。如果您只想启用特定的文本字段,请相应地修改.find('input[type=text]')
选择器的参数
如果还想切换只读
文本字段,请按如下方式操作:
$(this).parents('tr').find('input[name="WeightofDuties"]')
.attr('readonly', !this.checked);
是否要启用选定行中的所有td
文本框?