如何爲使用以下Javascript代碼創建的圖像添加鏈接?我嘗試了一些變化,但沒有奏效。如何使用Javascript爲圖像添加鏈接
請將以下代碼更改爲帶有鏈接的代碼。我想鏈接所有圖片http://idealbodyweights.com/。
<script type="text/javascript">
var image1 = new Image()
image1.src =="http://idealbodyweights.com/wp-content/uploads/2013/05/1.png"
var image2 = new Image()
image2.src = "http://idealbodyweights.com/wp-content/uploads/2013/05/2.png"
var image3 = new Image()
image3.src = "http://idealbodyweights.com/wp-content/uploads/2013/05/3.png"
var image4 = new Image()
image4.src = "http://idealbodyweights.com/wp-content/uploads/2013/05/4.png"
</script>
</head>
<body>
<p><img src="images/pentagg.jpg" width="720" height="90" name="slide" /></p>
<script type="text/javascript">
var step=4;
function slideit()
{
document.images.slide.src = eval("image"+step+".src");
if(step<4)
step++;
else
step=1;
setTimeout("slideit()",2500);
}
slideit();
</script>
不回答你的問題,但[你應該避免使用'eval'儘可能](http://stackoverflow.com/questions/86513/why-is-using-the-javascript- EVAL-功能-A-壞主意)。 –