不知道如何使用预加载的图像制作脚本
有人可以看一下这个并告诉我我必须做什么才能让图像显示出来吗?
<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- //Begin
function changeImage(filename)
{
mainimage.src = filename;
}
// End -->
</script>
</head>
<body>
<p>
<a href="javascript:changeImage('image-viewer/image1.jpg')">Image 1</a>
<a href="javascript:changeImage('image-viewer/image2.jpg')">Image 2</a>
<a href="javascript:changeImage('image-viewer/image3.jpg')">Image 3</a>
<a href="javascript:changeImage('image-viewer/image4.jpg')">Image 4</a>
</p>
<p>
<img name="mainimage" src="image-viewer/blank.jpg"></p>
<p><center>
<font face="arial, helvetica" size"-2">
</center><p>
</script>
</font></body>
</html>
Can someone look over this and tell me what I have to do to get the images to show up?
<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- //Begin
function changeImage(filename)
{
mainimage.src = filename;
}
// End -->
</script>
</head>
<body>
<p>
<a href="javascript:changeImage('image-viewer/image1.jpg')">Image 1</a>
<a href="javascript:changeImage('image-viewer/image2.jpg')">Image 2</a>
<a href="javascript:changeImage('image-viewer/image3.jpg')">Image 3</a>
<a href="javascript:changeImage('image-viewer/image4.jpg')">Image 4</a>
</p>
<p>
<img name="mainimage" src="image-viewer/blank.jpg"></p>
<p><center>
<font face="arial, helvetica" size"-2">
</center><p>
</script>
</font></body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将您的功能更改为:
Change your function to:
一个好朋友帮我查了一下
mainimage.src = filename;
是错误的,应该是应该是
然后是这样的:
mainimage.src = filename;< /code>
应该是
document.getElementById("mainimage").setAttribute("src", filename);
还有一个额外的
标签在最后。
不过,我认为她的形象定位问题更大。他需要有关项目的更多信息
编辑:可能会发生什么
她有 html 文件吗
在同一个文件夹中
如图像
这确实行不通。
因为如果她所有的文件都在
c:/图像查看器/
没有子目录
html 文件是
c:/image-viewer/index.html
。因此她需要一个新的图像文件夹因为脚本
正在要求
c:/image-viewer/image-viewer/image1.jpg
而不是 c:/image-viewer/image1.jpg
如果这不是为了上课,她需要学习编写符合标准的代码。查找 DOM,
如果所有文件都在一个文件夹中,那么她必须去掉文件名前面的
image-viewer/
。A good friend helped me look this up
mainimage.src = filename;
is wrong, and should instead be<img name="mainimage" src="image-viewer/blank.jpg">
should be
<img id ="mainimage" src="image-viewer/blank.jpg">
And then this:
mainimage.src = filename;
should be
document.getElementById("mainimage").setAttribute("src", filename);
there's an extra
tag in the end.
I think she's having more of a problem with her image locations, though. He needs more info about project
Edit : What might be happening
is she has the html file
in the same folder
as the images
which really won't work.
because if all her files are in
c:/image-viewer/
with no subdirectories
and the html file is
c:/image-viewer/index.html
. Therefore she needs a new folder for the imagesBecause the script
is asking for
c:/image-viewer/image-viewer/image1.jpg
as opposed to c:/image-viewer/image1.jpg
If this isn't for a class, she needs to learn to write standards compliant code. Look up DOM
if all the files are in one folder, then she has to do away with
image-viewer/
in front of the file names.