1

我想显示图像用户从 for 循环中的图像链接到 div 的点击。

我的 for 循环如下。

<a href='' name=my_image[i]

onclick='disp_image('link_image_url')'id=my_image[i]  class='popup-open'><img src=my_image[i] width='80' height='65'></a>;

和我的 javascript 函数

<script language=\"javascript\">


function disp_image(url){

document.getElementById('image').innerHTML ="<img src=url width='100' height='105'>";

;}

</script>


</script>

但是它没有加载到我的 div 内容中

<div id="image"></div>

有人可以知道如何在 div 内容中动态显示选定的图像

4

4 回答 4

2

用这个:

var _leng = my_image.length
  , td = "<td><a href='#url#' onclick='displaying(/image#url#)' id='/image#url#'><img src='#url#' width='80' height='65' /></a></td></tr><tr>"
  , i; 

for (i=0; i < _leng; i++) {
  str += td.replace(/#url#/g, my_image[i])
}

检查这个例子:http: //jsfiddle.net/hMfRG/

于 2012-11-22T19:41:55.600 回答
0
于 2012-11-22T19:16:57.370 回答
0

Look at the syntax highlighting of your post. You can clearly see that your quotes are all over the place. For instance, you have src='"+url+'", which is wrong. You also have "smart quotes" in places. Fix the quotes and it should stop throwing syntax errors.

But most importantly, your onclick function calls displaying(), whereas the function is called displayImage and takes an argument.

于 2012-11-22T19:17:26.233 回答
0

我是这样做的:

<div id="result" style="width:450px;height:296px;">
<img name="main" src="/images/image.jpg" alt="">
</div>

function change_pic(img_name,img_src) 
{
  document[img_name].src=img_src;
}
于 2012-11-22T19:19:58.563 回答