我在IE7中遇到了一些JS问题。我正在测试以查看某个对象是否具有分配的className(可能是来自DOM的HTMLElement对象)。现在Internet Explorer 7 - Javascript'undefined'not testing
,在Firefox测试的网页告诉我,是的,变量是不确定的(我所有的测试下面做警报()。
在IE中,没有一个测试通过,该变量被所分配的最后IF语句,并在最后警报()IE夹头的“类名是空或不是对象”错误的基础上,fn_note.className
声明
下面的代码:
var fn_note;
var kids = area.childNodes;
for (var l = 0; l < kids.length; l++){
//DEBUG check if the found var exists
if (kids[l].className == null){
//then the className var doens't exist
alert ('the classsname for the following var is null: --'+kids[l]+'--');
}
if (kids[l].className == undefined){
//then the className var doens't exist
alert ('the classsname for the following var is undefined: --'+kids[l]+'--');
}
if (kids[l].className == ''){
//then the className var doens't exist
alert ('the classsname for the following var is an empty string: --'+kids[l]+'--');
}
if (typeof kids[l].className === 'undefined'){
//then the className var doens't exist
alert ('the classsname for the following var is NEW TYPEOF TEST: --'+kids[l]+'--');
}
if (kids[l].className == 'fn-note') { /* (/fn-note$/).test(kids[l].className) IE doesn't really like regex. por supuesto */
//we have found the div we want to hide
fn_note = kids[l];
}
}
alert('the clicked on className is '+area.className+'name of the found div is '+fn_note.className);
请让我知道我做错了什么,我知道它可能有些基本的东西,但我不能看到它的ATM。
在此先感谢。
刚刚在IE7上测试过:http://jsbin.com/azoya/报告一个空字符串。 – strager 2009-02-26 02:29:33
也在这里测试过它,空字符串以及 – eglasius 2009-02-26 08:36:33