简体   繁体   English

如何检查表格中输入文本焦点的复选框

[英]How to check a checkbox on focus of Input text in table

I am trying to check a checkbox in table DOM on focus of input text, but am not able to access the checkbox element, but my focus is working 我正在尝试检查表DOM中关于输入文本焦点的复选框,但是无法访问checkbox元素,但是我的焦点正在工作

and here is my jsfiddle link https://jsfiddle.net/9qha9vft/ 这是我的jsfiddle链接https://jsfiddle.net/9qha9vft/

here is my code 这是我的代码

Jquery code jQuery代码

$("td .focus-evt").focus(function() {

$(this).siblings("td input.flat").prop('checked', true);;

});

Your input and checkbox aren't siblings, they are in different TD's. 您的输入和复选框不是同级,它们在不同的TD中。

Go to the closest TR, then find the TD and checkbox 转到最近的TR,然后找到TD和复选框

$("td .focus-evt").focus(function() {
    $(this).closest('tr').find("td input.flat").prop('checked', true);;
});

FIDDLE 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM