4
$("#test_point_geck_info")
  .html("<div id='img_1' class='img_1'>" +
     "<img src = " + ROOT_PATH + 
     "/assets/Capture.PNG onclick=PopImage(" + ROOT_PATH + 
     "/assets/Capture.PNG,'xyz')" +
     " style='cursor:pointer;' class=thumbnail width='100' height='100'></div>");

浏览器上的结果如下:

<img src="/assets/Capture.PNG" onclick="PopImage(/assets/Capture.PNG,'xyz')" style="cursor:pointer;" class="thumbnail" width="100" height="100">

正在调用的函数:

function PopImage(imagesrc,caption) {
var PopupImageContainer = new Image();
PopupImageContainer.src = PopupImageSRC;
setTimeout("PopupImageDisplay()",loadDelay);

}
4

2 回答 2

5

/assets/Capture.PNG被解释为带有 as 标志的正则表达式文字(for assets) Capture.PNG- 这是无效的。你想要一个字符串:'/assets/Capture.PNG'.

无论如何,您不应该使用内联事件处理程序属性——尤其是当您已经有 jQuery 可用时。更好的:

$("#test_point_geck_info").html('<div id="img_1" class="img_1">' +
'<img src = " + ROOT_PATH + "/assets/Capture.PNG" title="xyz" ' +
'class="thumbnail" width="100" height="100"></div>').find("img").click(PopImage);
function PopImage(e) {
    var imagesrc = this.src,
        caption = this.title;
    var PopupImageContainer = new Image();
    PopupImageContainer.src = PopupImageSRC;
    PopupImageContainer.onload = function() {
        PopupImageDisplay(PopupImageContainer, PopupImageCaption, PopupImageSRC);
    };
}
.thumbnail {
    cursor: pointer;
}
于 2013-07-01T16:06:26.697 回答
2

当在javascript之间错误地放置一些代码时发生在我身上

于 2015-08-19T11:19:13.170 回答