将图像链接到网络链接 [英] link images to web link

查看:179
本文介绍了将图像链接到网络链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我不是网页设计师,我对html,css,javascript等知识非常有限。

Firstly, I am not a web designer and I have very limited knowledge of html, css, javascript etc.

我正在运行一个显示随机图像的脚本每次刷新页面。我想知道,我如何设置点击链接,允许用户点击随机图像并进入另一个网页。

I am running a script which displays a random image each time the page is refreshed. I would like to know, how I can set a click through link that allows the user to click on the random image and follow through to another web page.

剧本即时通讯使用在下面。理想情况下,我希望能够点击图像然后发送到该单词的定义。

The script im using is below. Ideally, I'd like to be able to click on the image and then be sent to a definition of the word.

例如,当expose.png是显示,我希望能够点击图像并被带到, http:// oxforddictionaries.com/definition/english/expose?q=expose

For example, when "expose.png" is shown, id like to be able to click on the image and be taken to, http://oxforddictionaries.com/definition/english/expose?q=expose

请帮忙。

<a href="javascript:document.location.reload();"
ONMOUSEOVER="window.status='Refresh'; return true">
<img src="Graphic-design-can-[TEST].png" width="auto" height="auto"//>
</a>

</div>




<div id="outcome">

<script language="JavaScript">

function random_imglink(){
var myimages=new Array()

myimages[1]="expose.png"
myimages[2]="inform.png"
myimages[3]="explain.png"
myimages[4]="formulate.png"
myimages[5]="record.png"
myimages[6]="mediate.png"
myimages[7]="design.png"
myimages[8]="persuade.png"
myimages[9]="summarise.png"
myimages[10]="generate.png" 


var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()

</script>


推荐答案

你可以做类似的事情,相同的程序如图片代码,

You can do something similar to this, identical procedure as the image tags,

<a href="javascript:document.location.reload();"
ONMOUSEOVER="window.status='Refresh'; return true">
<img src="Graphic-design-can-[TEST].png" width="auto" height="auto"//>
</a>

</div>

<div id="outcome">

<script language="JavaScript">

function random_imglink(){
var myimages=new Array()
var myurls=new Array()

myimages[1]="expose.png"
myimages[2]="inform.png"
myimages[3]="explain.png"
myimages[4]="formulate.png"
myimages[5]="record.png"
myimages[6]="mediate.png"
myimages[7]="design.png"
myimages[8]="persuade.png"
myimages[9]="summarise.png"
myimages[10]="generate.png" 

myurls[1]="http://google.com"
myurls[2]="http://stackoverflow.com"
.....
....


var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href="'+myurls[ry]+'"><img src="'+myimages[ry]+'" border=0 id="'+myimages[ry]+'" onClick="'+dosomething(myimages[ry])+'") /></a>')
}

random_imglink()

function dosomething(myimage)
{
      switch(myimage)
      {
             case 'expose.png':
                     p = document.createElement("p");

                     img = document.createElement("img");
                     img.id="minutesTens";
                     img.src = "1.gif";
                     p.appendChild(img);
                     break;

             case 'inform.png':
                     p = document.createElement("p");

                     img = document.createElement("img");
                     img.id="minutesTens";
                     img.src = "2.gif";
                     p.appendChild(img);
                     break;
              case.....
              ..........
              ..........

 }

</script>

此代码说明:
使用document.write函数创建的图像将包含ID和事件调用onClick。
将使用参数ID调用onClick()函数。将传递当前图像的ID。

What this code says: The image which is being created with the document.write function will contain the ID and a event call "onClick". The function onClick() will be called with the parameter "ID". Where the ID of the current image will be passed.

dosomething()函数获取图像的ID并根据switch case语句设置下一个图像。
我希望现在很清楚。
希望它有所帮助。

The dosomething() function get the ID of the image and set the next image according to the switch case statements. I hope it is clear now. Hope it helps.

这篇关于将图像链接到网络链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆