Uncaught SyntaxError:提供给RegExp构造函数'Capture'的无效标志 [英] Uncaught SyntaxError: Invalid flags supplied to RegExp constructor 'Capture'
本文介绍了Uncaught SyntaxError:提供给RegExp构造函数'Capture'的无效标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$("#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
被解释为正则表达式文字(对于资产
),其中 Capture.PNG
作为标记 - 这是无效的。你想要一个字符串:'/ assets / Capture.PNG'
。
/assets/Capture.PNG
is interpreted as a regex literal (for assets
) with Capture.PNG
as flags - which are invalid. You wanted a string: '/assets/Capture.PNG'
.
无论如何,你不应该使用内联事件处理程序属性 - 尤其是当您已经有jQuery可用时。更好:
Anyway, you shouldn't use inline event handler attributes - especially when you already have jQuery available. Better:
$("#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;
}
这篇关于Uncaught SyntaxError:提供给RegExp构造函数'Capture'的无效标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文