Javascript 使用eval()在IE8和IE7中不起作用,但在IE9、FF和Chrome中起作用?
我在eval()方面有问题,我正在验证用户使用对象javascript提交的数据 例如Javascript 使用eval()在IE8和IE7中不起作用,但在IE9、FF和Chrome中起作用?,javascript,eval,Javascript,Eval,我在eval()方面有问题,我正在验证用户使用对象javascript提交的数据 例如 这项工作在IE8中进行,但在IE7中不进行。。。运气好吗?IE7/8不支持getElementsByClassName方法。您可以在MustChecked函数中使用它 不支持,如“不存在” 有垫片可用。快速谷歌搜索会给你一些结果。或者您可以使用Sizzle或简单的querySelectorAllshim,这是更通用的 如果您想知道某个功能是否受支持,最好的资源是。IE7/8不支持getElementsByCl
这项工作在IE8中进行,但在IE7中不进行。。。运气好吗?IE7/8不支持
getElementsByClassName
方法。您可以在MustChecked
函数中使用它
不支持,如“不存在”
有垫片可用。快速谷歌搜索会给你一些结果。或者您可以使用Sizzle或简单的querySelectorAll
shim,这是更通用的
如果您想知道某个功能是否受支持,最好的资源是。IE7/8不支持
getElementsByClassName
方法。您可以在MustChecked
函数中使用它
不支持,如“不存在”
有垫片可用。快速谷歌搜索会给你一些结果。或者您可以使用Sizzle或简单的querySelectorAll
shim,这是更通用的
如果你想知道某个功能是否受支持,那么一个好的资源就是。这个.MustChecked返回什么?它返回true或false。。。它检查是否有复选框被选中,如果它返回true或false,则没有理由在ifif中使用eval。MustChecked返回一个布尔值。您所要做的就是:
if(!this.MustChecked(…){}
在不知道实际被评估的内容的情况下真的帮不了什么忙。请尝试添加console.log()MustChecked()函数输出的
,以查看实际运行的内容。但总的来说,我的建议是尽可能避免eval()
——事实上,每当你看到eval()
,几乎总是有更好的方法来做事情。这个.MustChecked
返回什么?它返回真还是假。。。它检查是否有复选框被选中,如果它返回true或false,则没有理由在ifif中使用eval。MustChecked返回一个布尔值。您所要做的就是:if(!this.MustChecked(…){}
在不知道实际被评估的内容的情况下真的帮不了什么忙。请尝试添加console.log()MustChecked()函数输出的
,以查看实际运行的内容。但总的来说,我的建议是尽可能避免使用eval()
——事实上,每当你看到eval()
,几乎总会有更好的方法做事情。我的好朋友GetElementByClassName在IE7和IE8中不起作用。。我试着这样做。@AnthonyPillos QuerySelector都存在于IE8中,而不是IE7中。如果你想让它在IE7中工作,你需要包含一个垫片。你的权利,我的朋友,GetElementByClassName在IE7和IE8中不起作用。。我试着这样做。@AnthonyPillos QuerySelector都存在于IE8中,而不是IE7中。如果你想让它在IE7中工作,你需要包括一个垫片。
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"));
}
}
}
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;
},
getElementsByClassName : function (className) {
if (document.getElementsByClassName) {
return document.getElementsByClassName(className);
}
else {
return document.querySelectorAll('.' + className);
}
},