我有关于 eval() 的问题,我正在验证用户使用对象 javascript 提交的数据。
例如
for(var i=0;i<count;i++){
switch(caseType){
case: 'Group':
### it will execute the ff code
### it will call MustChecked function
if(!eval(this.MustChecked(getAttribute('class'), getAttribute('min'), getAttribute('max')))) {
####this will alert all the errors..
this.AddError(i, getAttribute("msg"));
}
}
}
从此代码中,它将警告所有错误...此代码在 IE8 和 IE7 中不起作用...任何人都知道为什么在 IE8 和 IE7 中不起作用?
更新:必须检查的功能
MustChecked : function(name, min, max) { var groups = document.getElementsByClassName(name); alert(groups); //console.log(name + ":" + groups.length); var hasChecked = 0; min = min || 1; max = max || groups.length; for(var i=groups.length-1;i>=0;i--) if(groups[i].checked) hasChecked++; return min <= hasChecked && hasChecked <= max; },
更新 V1.1
我试过这样
getElementsByClassName : function (className) {
if (document.getElementsByClassName) {
return document.getElementsByClassName(className);
}
else {
return document.querySelectorAll('.' + className);
}
},
这在 IE8 中有效,但在 IE7 中无效……运气好吗?