$("#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);
}
/assets/Capture.PNG
被解释为正则表达式文字 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Creating_a_Regular_Expression (for assets
) with 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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)