[英]Script causes IE6 to fallover with no error
I hate IE6, in fact I wish microsoft would force out a patch that killed the damn thing stone dead. 我讨厌IE6,事实上我希望微软能够推出一个补丁来杀死该死的石头。 The following script works fine in IE > 6 & FF,WebKit(chrome etal) without issue;
以下脚本在IE> 6&FF,WebKit(chrome etal)中没有问题,可以正常工作; any ideas?
有任何想法吗?
(function getElementsByClass(searchClass) {
node = document;
tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
var count = 1;
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
var re1='.*?'; // Non-greedy match on filler
var re2='(\\\'.*?\\\')'; // Single Quote String 1
var p = new RegExp(re1+re2,["i"]);
var m = p.exec(els[i].getAttribute("onclick"));
var popURL = "";
if (m != null)
{
var strng1=m[1];
popURL = strng1.replace(/'/g,'');
}
els[i].setAttribute("href", popURL + "?keepthis=true&tb_iframe=true&height=430&width=400");
els[i].setAttribute("class", "thickbox");
els[i].removeAttribute("onclick");
j++;
count++;
}
}
// return count; Ignore the return
})("vtthickbox");
typeof els[i].getAttribute("onclick")
returns function
in my IE6, but FF, Opera returns string
. typeof els[i].getAttribute("onclick")
在我的IE6中返回function
,但FF,Opera返回string
。
I don't think RegExp.exec
can handle function
object. 我不认为
RegExp.exec
可以处理function
对象。
And with that, typeof m[1]
became undefined
, which cause popURL
to undefined
too. 由此,类型
typeof m[1]
变得undefined
,这导致popURL
也undefined
。
Why not just use this instead: 为什么不直接使用它:
function getElementsByClass(searchClass) {
var classElements = new Array(),
node = document,
tag = '*',
els = node.getElementsByTagName(tag),
elsLen = els.length,
pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)"),
i,
j;
for (i = 0, j = 0; i < elsLen; i++) {
if (pattern.test(els[i].className)) {
classElements[j] = els[i];
j++;
};
};
return classElements;
};
Then put the onclick
event handler logic outside of the getElementsByClass()
function. 然后将
onclick
事件处理程序逻辑放在getElementsByClass()
函数之外。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.