[英]Ie7 javascript issue
I have following code its working one IE8, FF and other browser but is not working for IE7 on checking i found formatIncludes[i]
is not working, any idea whats wrong in this with IE7 and any work around 我有下面的代码,它可以在IE8,FF和其他浏览器上正常工作,但在检查是否发现
formatIncludes[i]
无效时,对于IE7却不起作用,任何想法在IE7中有什么问题以及其他解决方法
var formatIncludes = valueToSet.replace(/[^\D]/g, '');
for(var i=formatIncludes.length-1; i >= 0 ; i--){
if(valueToSet && valueToSet != null && valueToSet.endsWith(formatIncludes[i])){
valueToSet = valueToSet.substr(0, valueToSet.length - 1);
}else{
break;
}
}
String.prototype.endsWith = function(suffix) {
return (this.indexOf(suffix, this.length - suffix.length) != -1);
};
formatIncludes
can contain any string value formatIncludes
可以包含任何字符串值
error on IE7 IE7上的错误
Message: 'length' is null or not an object
Line: 352
Char: 2
Code: 0
URI: http://localhost:7001/HHSPortal/framework/skeletons/hhsa/js/util.js
It seems that indexing a string with [i]
does not work? 似乎用
[i]
索引字符串不起作用? And the more consistent/correct solution is to use .charAt(i)
而更一致/正确的解决方案是使用
.charAt(i)
The reasoning can be found in these: 可以在以下内容中找到原因:
string.charAt(x) or string[x]? 是string.charAt(x)还是string [x]?
JavaScript cross-browser: Is it safe to treat a string as array? JavaScript跨浏览器:将字符串视为数组是否安全?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.