不知道如何使用预加载的图像制作脚本

发布于 2024-09-12 18:27:35 字数 876 浏览 4 评论 0原文

有人可以看一下这个并告诉我我必须做什么才能让图像显示出来吗?

<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 技术交流群。

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

发布评论

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

评论(3

心欲静而疯不止 2024-09-19 18:27:35
<!DOCTYPE html>
<html>
    <head>
        <title>Sample page</title>   
        <script type="text/javascript">

        function changeImage(replacement)
        {
            document.getElementById("main_image").src = replacement;
            return false;   
        }

        </script>
    </head>
    <body>

        <ul>
            <li><a href="javascript:changeImage('image1.jpg')">Image 1</a></li>
            <li><a href="javascript:changeImage('image2.jpg')">Image 2</a></li>
            <li><a href="javascript:changeImage('image3.jpg')">Image 3</a></li>
            <li><a href="javascript:changeImage('image4.jpg')">Image 4</a></li>
        </ul>

        <p>
            <img id="main_image" src="image-viewer/blank.jpg" alt="" />
        </p>

    </body>
</html>
<!DOCTYPE html>
<html>
    <head>
        <title>Sample page</title>   
        <script type="text/javascript">

        function changeImage(replacement)
        {
            document.getElementById("main_image").src = replacement;
            return false;   
        }

        </script>
    </head>
    <body>

        <ul>
            <li><a href="javascript:changeImage('image1.jpg')">Image 1</a></li>
            <li><a href="javascript:changeImage('image2.jpg')">Image 2</a></li>
            <li><a href="javascript:changeImage('image3.jpg')">Image 3</a></li>
            <li><a href="javascript:changeImage('image4.jpg')">Image 4</a></li>
        </ul>

        <p>
            <img id="main_image" src="image-viewer/blank.jpg" alt="" />
        </p>

    </body>
</html>
风为裳 2024-09-19 18:27:35

将您的功能更改为:

function changeImage(filename) {
  document.main_image.src=filename;
  void(0);   
}

Change your function to:

function changeImage(filename) {
  document.main_image.src=filename;
  void(0);   
}
坚持沉默 2024-09-19 18:27:35

一个好朋友帮我查了一下

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 images

Because 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.

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