gpt4 book ai didi

javascript - 未捕获的语法错误 : Invalid flags supplied to RegExp constructor 'Capture'

转载 作者:搜寻专家 更新时间:2023-11-01 05:24:00 27 4
gpt4 key购买 nike

$("#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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com