javascript - 将 JavaScript 转换为 IE

标签 javascript internet-explorer

我有一个脚本,在我迄今为止测试过的所有浏览器(FF、Safari、camino、Chrome)中都可以正常工作,但在 IE 中却不能,我不明白为什么。 IE 8 (windows 7) 调试实用程序突出显示了脚本的这一部分:

if(list[lineNum].getElementsByClassName("check")[0].getElementsByTagName("a")[0].getAttribute("title").search("Delete")==0)

并说:

Object doesn't support this property or method

我想也许 IE 不喜欢列表数组,所以我在脚本的开头添加了一个显式声明

var list=new Array();

但我仍然遇到同样的错误。

我真的很想让这个在 IE 上运行,并且非常感谢任何帮助。

谢谢

最佳答案

Internet Explorer 没有 native getElementsByClassName 支持。有一个项目被很多人用作替代方案,it's available on Google Code here根据麻省理工学院的许可。

您的代码将类似于(未经测试,只是一个示例):

if(getElementsByClassName("check", null, list[lineNum])[0].getElementsByTagName("a")[0].getAttribute("title").search("Delete")==0)

不过,我真的建议使用 jQuery。它的构建就是为了让这些事情变得简单。

关于javascript - 将 JavaScript 转换为 IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2166694/

相关文章:

javascript - 使用 jquery 或 ajax 将值传递到另一个页面

javascript - 递归函数调用在 console.log() 上返回 [Circular]

jquery - 一个简单的 jQuery 脚本无法在 IE 中运行 - 认为 jQuery 是跨平台的!

css - 页面布局适用于 IE 和 Firefox,但不适用于 Chrome

javascript - 使用 Internet Explorer 打印 html 页面

internet-explorer - ADFS 3.0/2012R2 身份验证在 IE 中失败

javascript - JS : orientationchange before?

javascript - 切换 Div 显示/隐藏

javascript - 单击正文时显示和隐藏菜单

javascript - Internet Explorer getClientRects 绝对定位元素