javascript 未捕获的 SyntaxError:提供给 RegExp 构造函数“Capture”的标志无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17408817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught SyntaxError: Invalid flags supplied to RegExp constructor 'Capture'
提问by Vinay
$("#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>");
Results following on the browser:
浏览器上的结果如下:
<img src="/assets/Capture.PNG" onclick="PopImage(/assets/Capture.PNG,'xyz')" style="cursor:pointer;" class="thumbnail" width="100" height="100">
function that am calling :
正在调用的函数:
function PopImage(imagesrc,caption) {
var PopupImageContainer = new Image();
PopupImageContainer.src = PopupImageSRC;
setTimeout("PopupImageDisplay()",loadDelay);
}
回答by Bergi
/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'
.
/assets/Capture.PNG
被解释为带有as 标志的正则表达式文字(for assets
) Capture.PNG
- 这是无效的。你想要一个字符串:'/assets/Capture.PNG'
。
Anyway, you shouldn't use inline event handler attributes - especially when you already have jQuery available. Better:
无论如何,您不应该使用内联事件处理程序属性——尤其是当您已经有可用的 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;
}
回答by Ebrahim
It occurred for me when incorrectly put some codes between javascript
当我在 javascript 之间错误地放置一些代码时发生了这种情况