hol*_*den 4 jquery children input jquery-selectors
我想从复选框中做下面的事情,
每行都有一个复选框,我想在单击复选框时禁用类.room的行中的所有输入字段.
function toggleStatus(link) {
$(link).closest(".room").children(':input').attr('disabled', true);
}
Run Code Online (Sandbox Code Playgroud)
也试过了
function toggleStatus(link) {
$(link).closest(".room").children('input[type=text]').attr('disabled', true);
}
Run Code Online (Sandbox Code Playgroud)
您的问题有些含糊不清,因此以下内容可能并不完全符合您的要求.
单击后,您应该遍历到最近的表行,找到具有类名的所有输入,.room并根据复选框本身的状态设置其disabled属性.
$(":checkbox").click(function(){
$(this).closest("tr").find(":input.room")
.attr("disabled", $(this).is(":checked"));
});
Run Code Online (Sandbox Code Playgroud)
假设结构类似于以下结构:
<table>
<tbody>
<tr>
<td><input type="checkbox" /></td>
<td><input type="text" class="room" /></td>
<td><input type="text" class="room" /></td>
<td><input type="text" class="room" /></td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td><input type="text" class="room" /></td>
<td><input type="text" class="room" /></td>
<td><input type="text" class="room" /></td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
在线演示:http://jsbin.com/umimu/edit