javascript 和图像映射问题

发布于 2024-08-18 13:38:33 字数 1078 浏览 6 评论 0原文

我承认,我是一个 javascript 菜鸟。我当前任务的一部分是,当用户将鼠标悬停在第一个 .png 的左上角时,我尝试将 .png 文件替换为另一个 .png 文件。当他将鼠标移开时,.png 需要恢复为初始 .png 文件。

我正在尝试使用图像映射和 java 脚本来完成此任务。我在第 17 行收到以下错误:

'StaticImage1 is undefined"

第 17 行是下面的“area coords=...”行:

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Hot Spot Test</title>
<script language="javascript" type="script">
loadImageUL = new Image();
loadImageUL.src = "images/image2.png";
staticImage1 = new Image();
staticImage1.src = "images/image2.png";
</script>
</head>
<body>
    <p>
    <map id="FPMap1" name="FPMap1">
        <area coords="0, 0, 111, 96" href="http://thepcparamedics.com/" shape="rect"  onmouseover="image1.src=loadImageUL.src;" onmouseout="image1.src=staticImage1.src;" />
    </map>
    <img name="image1" alt="" height="203" src="images/image1.png" width="234" usemap="#FPMap1" />
</p>
</body>

我知道我一定错过了一些简单的东西。预先感谢您的帮助。

麦克风

I confess, I'm a javascript noob. Part one of my current task is I'm trying to get a .png file to be replaced with another .png when the user mouses over the upper left corner of the first .png. When he mouses off, the .png needs to revert back to the initial .png file.

I'm trying to use an image map and java script to accomplish this. I am getting the following error on line 17:

'StaticImage1 is undefined"

Line 17 is the "area coords=..." line below:

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Hot Spot Test</title>
<script language="javascript" type="script">
loadImageUL = new Image();
loadImageUL.src = "images/image2.png";
staticImage1 = new Image();
staticImage1.src = "images/image2.png";
</script>
</head>
<body>
    <p>
    <map id="FPMap1" name="FPMap1">
        <area coords="0, 0, 111, 96" href="http://thepcparamedics.com/" shape="rect"  onmouseover="image1.src=loadImageUL.src;" onmouseout="image1.src=staticImage1.src;" />
    </map>
    <img name="image1" alt="" height="203" src="images/image1.png" width="234" usemap="#FPMap1" />
</p>
</body>

I know I must be missing something simple. Thanks in advance for your assistance.

Mike

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

以歌曲疗慰 2024-08-25 13:38:33

您的脚本类型应为text/javascript,并且您可以省略语言

Your script type should be text/javascript, and you can leave out the language

追我者格杀勿论 2024-08-25 13:38:33

好的。因此,代码存在一些与问题无关的问题。例如StaticImageUL和StaticImage2都被分配为image2.png。

话虽这么说,错误的原因是由于 script 元素中的 Type="script" 造成的。我将其更改为 type="" 并且代码似乎可以按预期工作。

OK. So there were a few issues with the code unrelated to the problem. Such as StaticImageUL and StaticImage2 both being assinged image2.png.

That being said, the cause of the error was due to the Type="script" in the script element. I changed this to type="" and the code seems to work as desired.

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