[英]Using eval() not work in IE8 and IE 7 but works in IE9, FF,Chrome?
我有關於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中無效...運氣如何?
IE7 / 8不支持getElementsByClassName
方法。 然后在MustChecked
函數中使用它。
不支持,因為“不存在”中。
有墊片。 快速谷歌搜索會給你一些結果。 或者,您可以使用Sizzle或簡單地使用querySelectorAll
shim,它們更加通用。
如果要確定是否支持某項功能,可以使用caniuse.com作為一個很好的資源。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.