选中/取消选中MVC视图中的所有复选框 [英] Check /uncheck all check boxes in MVC view
本文介绍了选中/取消选中MVC视图中的所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
选中/取消选中MVC视图中的所有复选框
i有两行checkboX.each行第一行i check\uncheck,它影响第一行或第二行< br $>
我的小提琴---- http://jsfiddle.net/fA2w5/ 128 / [ ^ ]
Check /uncheck all check boxes in MVC view
i have two row checkboX.each row first line i check\uncheck,it affects first or second line
my fiddle----http://jsfiddle.net/fA2w5/128/[^]
<input type="checkbox" name="Test1" onclick="SetAllCheckBoxes(this)"/>
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
</br>
<input type="checkbox" name="Test2" onclick="CheckBox(this)"/>
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
function SetAllCheckBoxes(obj) {
var c = new Array();
c = document.getElementsByTagName('input');
for (var i = 0; i < c.length; i++) {
if (c[i].type == 'checkbox') {
c[i].checked = obj.checked;
}
}
}
function CheckBox(obja) {
var d = new Array();
d = document.getElementsByTagName('input');
for (var i = 0; i < d.length; i++) {
if (d[i].type == 'checkbox') {
d[i].checked = obja.checked;
}
}
}
http://jsfiddle.net/fA2w5/128/ [ ^ ]
推荐答案
我编辑了你的jsfiddle,不确定这是否正是你所需要的,但我希望它会有所帮助。
http://jsfiddle.net/5L7q4dsc/ [ ^ ] < br $>
选中/取消选中:
http://jsfiddle.net/mcptsuto/ [ ^ ]
Hi, I edited your jsfiddle, not sure if that is exactly what you need, but I hope it will help.
http://jsfiddle.net/5L7q4dsc/[^]
check/uncheck:
http://jsfiddle.net/mcptsuto/[^]
编辑:我粘贴了一个更新的解决方案,但是看到这个被低估了,所以其他人可以提供帮助:)
I pasted an updated solution but saw this was down-voted so someone else can help :)
这篇关于选中/取消选中MVC视图中的所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文