JavaScript 图像更改错误
今天刚加入就已经喜欢这个网站了。
我的问题是。 我正在尝试为我的网站创建 6 个菜单。 像例如 { 家,关于我们,服务 ..... } 我希望只要用户鼠标悬停在菜单上,图像就会改变。 我实际上是从网上获得了这张纸条。 但它是一个图像的例子下面是代码: JavaScript / DHTML / AJAX 语法(切换纯文本)
function roll_over(img_name, img_src)
{
document[img_name].src = img_src;
}
以及正文 JavaScript / DHTML / AJAX 语法(切换纯文本)
<A HREF="some.html" onmouseover="roll_over('but1', 'icon2.gif')"
onmouseout="roll_over('but1', 'icon1.gif')">
<IMG SRC="icon1.gif" WIDTH="100" HEIGHT="50"
NAME="but1" BORDER="0">
</A>
现在我尝试将这五次相乘,(只是重复代码并更改图片名称) - 但每当我将鼠标悬停在图像上时,它们都不会改变。
所以我的问题是:如何将上述代码从一个图像转换器变成 6 个?
谢谢 !
just joined today loved this site already.
My Question is that. i am trying to create 6 Menus for my Web. like Eg { home, about us, service ..... } and i want the images to change whenever the users mouse hovers the menu's. I got the scrip actually from online souce. But it was an example for one image Here are the codes:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function roll_over(img_name, img_src)
{
document[img_name].src = img_src;
}
And for the body
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<A HREF="some.html" onmouseover="roll_over('but1', 'icon2.gif')"
onmouseout="roll_over('but1', 'icon1.gif')">
<IMG SRC="icon1.gif" WIDTH="100" HEIGHT="50"
NAME="but1" BORDER="0">
</A>
Now i tried to multiply these five times, ( just repeated the codes and changed the picture name ) - But whenever i hover on the images they do not change.
So my Q - is: How do you make the above code from a one image changer to 6?
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
评论(2)
尝试为每个图像使用一个
id
(id
必须是唯一的,因此不应该有具有相同id
的元素):并且此代码:
Try using an
id
for each image (id
must be unique, so there should be no elements with the sameid
):And this code:
好的,我想通了。 应该为每个图像设置一个唯一的名称。
试试这个代码
JavaScript / DHTML / AJAX 语法(切换纯文本)
希望这有效
Ok I figured it out. Should set a unique name for every Image.
Try this code
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
hope this works