尝试根据表格中的值选中一个复选框

时间:2015-01-08 18:28:27

标签: jquery checkbox

我正在尝试使用jQuery循环表中的行,如果第一个td具有某个值,则在该行上查找复选框并检查它。

$('#table1').find('tr').each(function(){
    var prod = $(this).find('td:first').text();
    if(prod == 'string value'){
        $(this).find('input[type=radio]').prop('checked', true); 
    alert(prod);
    }
});

但这不起作用。警报显示文本与第一个单元格中的文本匹配,但不会勾选最后一个单元格中的单选按钮。 不知道我在做错了什么

我使用类似的代码来选择基于单击行的复选框,这样可以正常工作。

$('#table1').find('tr').click( function(){
  var row = $(this).find('td:first').text();
  $(this).find('input[type=radio]').prop('checked', true);    
}); 

非常感谢任何帮助。

0 个答案:

没有答案