我有一个表格,其中显示了电子邮件收件箱(请参见摘录ss here)。
当用户点击复选框时,我应该使用正确的项目填充2个下拉列表。
function fnHandleSelectCBClick(cb) {
try {
var tableRow = $(cb).parent().parent();
// Here I should be able to find control ids of other 2 dropdown in the table row.
// Tried below code and failed
//var propSelect = $(cb).parent().parents('tr:first').find('select');
//var taskSelect = $(cb).parent().parents('tr:second').find('select');
} catch (e) {alert(e);}
}
Here是表格行结构截图 如果我可以得到他们的ID,我可以直接填写项目,然后它也可以验证 我是初学javascript和jQuery。如果我在任何地方都错了,请更正。
答案 0 :(得分:1)
您尚未显示表格和按钮的完整html,因此您可能需要根据ID,类名等进行调整。
$('#YourTableID').on('click', 'button', function() {
var row = $(this).closest('tr');
var selects = row.find('select');
var first = selects.first(); // this is the first select
var second = selects.last(); // this is your second select
});