繁体   English   中英

使用eval()在IE8和IE 7中不起作用,但在IE9,FF,Chrome中起作用?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM