jQuery按钮单击以选中复选框 [英] Jquery button click to select check box

查看:103
本文介绍了jQuery按钮单击以选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有包含用户数据的网格,其中第一列具有复选框.我在网格顶部有一个按钮.如果单击按钮,则需要从列表中选择前5名用户.

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.

有人可以告诉我如何使用jquery做到这一点吗?

Can anybody tell me how to do this using jquery?

推荐答案

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

如果网格中还有其他复选框,则可能存在问题.这是我最好的办法,而又看不到您的HTML.

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

这篇关于jQuery按钮单击以选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆