Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在脚本中添加指向图像的链接_Javascript - Fatal编程技术网

Javascript 在脚本中添加指向图像的链接

Javascript 在脚本中添加指向图像的链接,javascript,Javascript,此脚本用数组中列出的图像替换DIV“middle”的背景。目前的脚本工程完美,但我想能够分配一个链接到每个图像,尝试只是替换,但然后图像不显示,也没有链接的工作 <script> var images=new Array('/images/home/imgone.jpg', '/images/home/imgtwo.jpg', '/images/home/imgthree.jpg', '/images/home/imgfour.jpg', '/images/home/imgfive.

此脚本用数组中列出的图像替换DIV“middle”的背景。目前的脚本工程完美,但我想能够分配一个链接到每个图像,尝试只是替换,但然后图像不显示,也没有链接的工作

<script>
var images=new Array('/images/home/imgone.jpg', '/images/home/imgtwo.jpg', '/images/home/imgthree.jpg', '/images/home/imgfour.jpg', '/images/home/imgfive.jpg');
var nextimage=0;
doSlideshow();

function doSlideshow(){
if(nextimage>=images.length){nextimage=0;}
$('.middle')
.css('background-image','url("'+images[nextimage++]+'")')
.fadeIn(500,function(){
    setTimeout(doSlideshow,5000);
});
}
</script>

var images=新数组('/images/home/imgone.jpg','/images/home/imgtwo.jpg','/images/home/imgthree.jpg','/images/home/imgfour.jpg','/images/home/imgfive.jpg');
var-nextimage=0;
doSlideshow();
函数doSlideshow(){
如果(nextimage>=images.length){nextimage=0;}
$(“.middle”)
.css('background-image','url('+images[nextimage++]+''))
.fadeIn(500,函数(){
设置超时(doSlideshow,5000);
});
}
我要找的是这样的东西

<script> 
var images=new Array('/images/home/imgone.jpg', '/images/home/imgtwo.jpg', '/images/home/imgthree.jpg', '/images/home/imgfour.jpg', '/images/home/imgfive.jpg'); To: var images=new Array('<a href="linkone"><img src="/images/home/imgone.jpg"</a>', '<a href="linktwo"><img src="/images/home/imgtwo.jpg"</a>', '<a href="linkthree"><img src="/images/home/imgthree.jpg"</a>', '<a href="linkfour"><img src="/images/home/imgfour.jpg"</a>', '<a href="linkfive"><img src="/images/home/imgfive.jpg"</a>');
</script>

var images=新数组('/images/home/imgone.jpg','/images/home/imgtwo.jpg','/images/home/imgthree.jpg','/images/home/imgfour.jpg','/images/home/imgfive.jpg');To:var images=新数组(“”、“”、“”、“”、“”);

虽然这并不能完全回答您的问题,但您可以从DOM函数中获得一些想法

示例


//创造形象
var image=document.createElement(“img”);
//设置图像属性
image.src=”http://i.imgur.com/gqdqudn.png";
image.width=“30”;
image.height=“30”;
//将图像添加到主体
document.body.appendChild(图像);
这会将图像附加到主体。如果要将其添加到特定ID,可以执行以下操作(假设div ID为“destination”)

示例


//创造形象
var image=document.createElement(“img”);
//设置图像属性
image.src=”http://i.imgur.com/gqdqudn.png";
image.width=“30”;
image.height=“30”;
//将图像添加到主体
document.getElementById(“目的地”).appendChild(图像);

祝你好运

您想在哪里添加链接?您希望该链接做什么?寻求调试帮助的问题(“为什么该代码不工作?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现该问题所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:。检查此url。
<script>

  // Creates Image
  var image = document.createElement("img");

  // Sets Image Attributes
  image.src = "http://i.imgur.com/gqdqudn.png";
  image.width = "30";
  image.height = "30";

  // Adds Image to Body
  document.body.appendChild(image);

</script>
<!DOCTYPE html>

<html>

<body>

  <div id="destination">

    <!-- Destination Div -->

  </div>

<script>

  // Creates Image
  var image = document.createElement("img");

  // Sets Image Attributes
  image.src = "http://i.imgur.com/gqdqudn.png";
  image.width = "30";
  image.height = "30";

  // Adds Image to Body
  document.getElementById("destination").appendChild(image);

  </script>

</body>

</html>