IE 中的 Javascript 错误(翻转)

发布于 2024-07-26 12:07:48 字数 631 浏览 1 评论 0原文

我有一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浊酒尽余欢 2024-08-02 12:07:48

该错误表明您尝试按名称更改的图像不存在。 但是,除非您确切地发布了如何调用该方法(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.

浮萍、无处依 2024-08-02 12:07:48

你是不是缺少一个“.name”=> document.images[名称].src = ...

Aren't you lacking a ".name" => document.images[name].src = ...

萌梦深 2024-08-02 12:07:48

尝试 document.getElementsByName(name) 而不是 document[name]

try document.getElementsByName(name) instead of document[name]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文