jQuery 禁用 div 的多个输入子项
我想从复选框执行如下操作,
每行都有一个复选框,并且我想在单击该复选框时禁用 .room 类的行上的所有输入字段。
function toggleStatus(link) {
$(link).closest(".room").children(':input').attr('disabled', true);
}
也尝试过
function toggleStatus(link) {
$(link).closest(".room").children('input[type=text]').attr('disabled', true);
}
I want do do something like below from a checkbox,
There's a checkbox on every row, and I'd like to disable all the input fields on a row with the class .room when the checkbox is clicked.
function toggleStatus(link) {
$(link).closest(".room").children(':input').attr('disabled', true);
}
also tried
function toggleStatus(link) {
$(link).closest(".room").children('input[type=text]').attr('disabled', true);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题有些含糊不清,因此以下内容可能不完全是您要查找的内容。
单击后,您应该遍历到最近的表行,找到具有类名
.room
的所有输入,并根据复选框本身的状态设置其禁用属性。其结构类似于以下内容:
在线演示:http://jsbin.com/umimu/edit
Your question has some ambiguities, so the following may not be exactly what you're looking for.
Upon click, you should traverse up to the nearest table-row, find all inputs having the classname
.room
and set their disabled-attribute according to the status of the checkbox itself.This assumes a structure similar to that which follows:
Online Demo: http://jsbin.com/umimu/edit