开发者

Jquery button click to select check box

I have grid with user data with first column having check box. I have 开发者_如何转开发a button at the top of the grid. If I click button I need to select top 5 users from the list.

Can anybody tell me how to do this using jquery?


$('#myButton').click(function() {
    $('#Grid input[type=checkbox]:lt(5)').attr('checked','checked');
});

If you have other checkboxes in the grid, there may be in issue. This is the best I can do without seeing your HTML.


I found this in jQuery Doc

Because :lt() is a jQuery extension and not part of the CSS specification, queries using :lt() cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. For better performance in modern browsers, use $("your-pure-css-selector").slice(0, index) instead.

Base on the accepted answer you can do this:

$('#myButton').click(function() {
    $("#Grid input[type=checkbox]").slice(0,5).attr('checked','checked');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜