问题描述
我使用Ryan Fait的自定义表单元素创建了一个简单的表单。现在我想实现一个检查所有/全部取消选中功能。
I've made a simple form using Ryan Fait's Custom Form Elements. Now I am trying to implement a "Check All"/"Uncheck All" function.
我大部分的工作,除了用户必须点击按钮两次才能得到所需的结果。我有一种感觉,我需要从自定义表单元素脚本内调用此函数,但我不知道如何。
What I have mostly works, except that the user has to click the buttons twice to get the desired result. I have a feeling that I need to call this function from inside the Custom Form Elements script, but I don't know how.
我使用JQuery,自定义表单元素(http://ryanfait.com/resources/custom-check-boxes-and-radio-buttons/custom-form-elements .js),并且:
I'm using JQuery, Custom Form Elements (http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/custom-form-elements.js), and this:
<script type = "text/javascript">
function cboxToggle(group, action) {
for( var i=0, len = group.length; i < len; i++) {
group[i].checked = action;
}
}
</script>
我的HTML:
<form name="myname" action="checkboxes.asp" method="post">
<input type = "button" value = " CHECK ALL" onclick = "cboxToggle(check_list, !this.checked)"><br>
<input type = "button" value = " UNCHECK ALL" onclick = "cboxToggle(check_list, this.checked)"><br>
<p><input type="checkbox" name="check_list" value="1" class="styled" />Option 1 </p>
<p><input type="checkbox" name="check_list" value="2" class="styled" />Option 2 </p>
<p><input type="checkbox" name="check_list" value="3" class="styled" />Option 3 </p>
</form>
任何帮助将不胜感激 - 感谢!
Any help would be appreciated -- thanks!
推荐答案
查看以下网址
Uncheck checkbox in custom form elements
这篇关于“全部检查”函数,当使用Ryan Fait的“自定义表单元素”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!