javascript 和图像映射问题
我承认,我是一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的脚本
类型
应为text/javascript
,并且您可以省略语言
Your script
type
should betext/javascript
, and you can leave out thelanguage
好的。因此,代码存在一些与问题无关的问题。例如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.