选中所有复选框 [英] Select all checkboxes
本文介绍了选中所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Rails应用程序中,我创建了一组复选框,如下所示:
In my Rails app I've created a set of checkboxes as follows:
<div class="form_row">
<label for="features[]">Features:</label>
<% ['scenarios', 'news', 'role_profiles', 'private_messages', 'chatrooms', 'forums', 'polls'].each do |feature| %>
<br><%= check_box_tag 'features[]', feature, (@features || {}).include?(feature) %>
<%= feature.humanize %>
<% end %>
</div>
我想知道如何创建一个全选按钮。
I'd like to know how to create a button that would "Select All".
推荐答案
使用jQuery;
<script type="text/javascript">
function selectAll(){
$("input:checkbox").each(function(){
$(this).attr('checked', true);
});
return false;
}
</script>
HTML按钮:
<a href="#" onclick="selectAll()">Select All</a>
这篇关于选中所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文