IE 中的 Javascript 错误(翻转)
我有一些 javascript 滚动代码在 Firefox 中运行良好,但是当我在 IE 中尝试时出现此错误:
消息:“文档[...]”为空或不是对象 线路:25 字符:13 代码:0 URI:http://www.jgm-design.com/
我使用的代码是:
if (document.images)
{
image1 = new Image;
image2 = new Image;
image1.src = "images/logos/logoBlackFadedLow.jpg";
image2.src = "images/logos/logoWhiteFadedLow.jpg";
}
function chgImg(name, image)
{
if (document.images)
{
document[name].src = eval(image+".src");
}
}
任何知道为什么吗? 或者解决方案?
i have some javascript roll over code that works fine in firefox but when i try it in IE i get this error:
Message: 'document[...]' is null or not an object
Line: 25
Char: 13
Code: 0
URI: http://www.jgm-design.com/
the code im using is:
if (document.images)
{
image1 = new Image;
image2 = new Image;
image1.src = "images/logos/logoBlackFadedLow.jpg";
image2.src = "images/logos/logoWhiteFadedLow.jpg";
}
function chgImg(name, image)
{
if (document.images)
{
document[name].src = eval(image+".src");
}
}
Any idea why? Or a solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该错误表明您尝试按名称更改的图像不存在。 但是,除非您确切地发布了如何调用该方法(chgImg)以及您的 HTML 是什么,否则我无法真正为您提供具体帮助。
PS:这是一些相当过时的代码。 考虑使用 css :hover 伪类来解决这个问题,以及找到一些更新的 javascript 来处理这个问题,这将是一个好主意。
The error indicates that the image you're trying to change by name doesn't exist. Unless you post exactly how you're calling the method (chgImg) and what your HTML is, however, I can't really help you specifically.
PS: This is some quite outdated code. It would be a good idea to consider using css :hover pseudo-classes for this problem, as well as finding some more recent javascript to work with.
你是不是缺少一个“.name”=>
document.images[名称].src = ...
Aren't you lacking a ".name" =>
document.images[name].src = ...
尝试 document.getElementsByName(name) 而不是 document[name]
try document.getElementsByName(name) instead of document[name]