Uncaught SyntaxError:提供给RegExp构造函数'Capture'的无效标志

时间:2013-07-01 16:01:42

标签: javascript jquery jquery-ui javascript-events

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

}

2 个答案:

答案 0 :(得分:5)

/assets/Capture.PNG被解释为regex literal(对于assetsCapture.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;
}

答案 1 :(得分:2)

在javascript

之间错误地输入了一些代码时,我发生了这种情况