我试图在输入文本的焦点上检查表 DOM 中的复选框,但无法访问复选框元素,但我的焦点正在工作
这是我的 jsfiddle 链接 https://jsfiddle.net/9qha9vft/
这是我的代码
Jquery代码
$("td .focus-evt").focus(function() {
$(this).siblings("td input.flat").prop('checked', true);;
});
最佳答案
您的输入和复选框不是同级,它们位于不同的 TD 中。
转到最近的 TR,然后找到 TD 和复选框
$("td .focus-evt").focus(function() {
$(this).closest('tr').find("td input.flat").prop('checked', true);;
});
关于javascript - 如何选中表格中输入文本焦点上的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45358888/