2017-07-27 49 views
1

我想您在輸入文本的對焦表DOM複選框,但我不能夠訪問複選框元素,輸入文本的焦點,但我的重點工作如何檢查複選框上表

這裏是我的jsfiddle鏈接https://jsfiddle.net/9qha9vft/

這裏是我的代碼

jQuery代碼

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

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

}); 

回答

4

你的輸入和複選框不是兄弟姐妹,它們在不同的TD中。

轉到最近的TR,然後找到TD和複選框

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

FIDDLE