HTML code
全选和取消 怎么处理function bindEvent(fun) {
var args = [];
for(var i = 1; i < arguments.length; i++) {
args.push(arguments[i]);
}
return function() {
fun.apply(this, args);
};
}
function addCheckAllEvent(name, chk1, chk2) {
var chks = document.getElementsByName(name);
for(var i = 0; i < chks.length; i++) {
chks[i].checked = this.checked;
chks[i].mouseSelect = this.checked;
}
var chk = chk1 == this ? chk2 : chk1;
chk.checked = this.checked;
}
function addCheckEvent(chk1, chk2) {
if(!this.checked && !this.mouseSelect) {
this.checked = true;
this.mouseSelect = true;
return;
}
this.mouseSelect = this.checked ? true : false;
if(!this.checked && chk1.checked) {
chk1.checked = chk2.checked = false;
}
}
window.onload = function() {
var chk1 = document.frm.chk1;
var chk2 = document.frm.chk2;
var name = 'item';
var chks = document.getElementsByName(name);
for(var i = 0; i < chks.length; i++) {
chks[i].mouseSelect = false;
chks[i].onclick = bindEvent(addCheckEvent, chk1, chk2);
chks[i].onmouseover = function() {
this.checked = true;
};
chks[i].onmouseout = function() {
if(!this.mouseSelect) {
this.checked = false;
}
}
}
chk1.onclick =
chk2.onclick = bindEvent(addCheckAllEvent, name, chk1, chk2);
}
全选
选项一
选项二
选项三
选项四
选项五
选项六
选项七
选项八
全选
------解决方案--------------------
今天手气不错,此段代码一次写成,没debug,
下面代码适应性很强,其实你不需要like匹配功能你用的时候checkbox名字都取成一样的例如abc就行了,后台得到的是一个数组,遍历数组删除就行了,checkbox的value就是要删除对象的idHTML code
Insert title hereString.prototype.startWith = function(chars){
var matchString = new RegExp("^" + chars) ;
return this.match(matchString) != null ;
}
function demo(isChk,name){
var es=document.getElementsByTagName("input");//必要的时候这里可以优化速度
for(var i=0;i
var eck=es[i];
if(eck.type=='checkbox'&&eck.name.startWith(name)){
eck.checked=isChk;
}
}
}
全选
我是用于对比的