选择 FORM_TAG 中的所有复选框
在 form_tag
中,有一个包含 10 到 15 个复选框的列表:
<%= check_box_tag 'vehicles[]', car.id %>
如何通过 RJS 选择所有(在每个单独的复选框中打勾)复选框?谢谢
编辑:抱歉我没有说清楚我的问题。我的意思是问如何在同一页面中添加“选择/取消全选”链接来切换复选框。
In a form_tag
, there is a list of 10 to 15 checkboxes:
<%= check_box_tag 'vehicles[]', car.id %>
How can I select-all (put a tick in every single) checkboxes by RJS? Thanks
EDIT: Sorry I didn't make my question clear. What I meant to ask is how to add a "Select/Un-select All" link in the same page to toggle the checkboxes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
编辑
您可以使用 Tim Down 的解决方案作为普通的 javascript 解决方案。如果你使用 jQuery,你可以尝试这样的事情:
Try this:
Edit
You can use Tim Down's solution for vanilla javascript solution. If you are using jQuery, you can try something like this:
以下函数将切换特定 DOM 元素(例如
The following function will toggle the checkedness of all checkboxes inside a particular DOM element (for example, a
<form>
element):