0

我有 Telerik MVC Grid 与带有复选框的数据绑定。现在我需要根据条件检查复选框。在网格中,我有一个字段“IsSelected”,它是字符串。如果“IsSelected”为真,则仅应在网格中选中复选框。我需要使用 jquery 执行此操作。

4

3 回答 3

0

不确定 IsSelected 是属性... JS 变量...还是后端...

但无论哪种方式,基本逻辑都是......

jsFiddle 演示

// obviously specify the checkboxes more than this
$('input:checkbox').each(function () {
    if ( $(this).attr('IsSelected') === 'true' ) {
        $(this).prop('checked', true);
    }
});
于 2012-08-10T14:15:04.890 回答
0
if($('#IsSelected').val() == 'true'){
    $('#mygrid').find('input[type=checkbox]').attr('checked', true);
}
于 2012-08-10T14:17:20.883 回答
0

像这样的东西?

$('tbody > tr').each(function(){  // <-- loop through each row
    var $this = $(this);
    var $td = $this.children();
    if($td.eq(indexOfIsSelected).text() == 'true){  // <-- check the IsSelected column for text value
       $this.find('input[type=checkbox]').prop('checked',true);  // <-- if true then check checkbox in that row
    }
});
于 2012-08-10T14:21:45.983 回答