gpt4 book ai didi

javascript - Internet Explorer 7 - Javascript 'undefined' 未测试

转载 作者:行者123 更新时间:2023-12-02 07:56:40 25 4
gpt4 key购买 nike

我在 IE7 中遇到一些 JS 问题。我正在测试某个对象是否分配了 className(它可能是来自 DOM 的 HTMLElement 对象)。

现在,在 Firefox 中测试页面告诉我是的,变量未定义(我下面的所有测试都执行 Alert()。

在 IE 中,没有一个测试通过,变量在最后一个 IF 语句中被赋值,并且在最后一个 Alert() 期间,IE 根据 fn_note 查出一个“className is null or not an object”错误.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 上看不到它。

提前致谢。

最佳答案

我认为你从属性中得到的不是字符串,而是“未定义”类型的对象。试试这个:

if (typeof(kids[l].className) == 'undefined') {

关于javascript - Internet Explorer 7 - Javascript 'undefined' 未测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/588845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com