$("#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
被解释为 regex literal (对于 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;
}
关于javascript - 未捕获的语法错误 : Invalid flags supplied to RegExp constructor 'Capture' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17408817/