简体   繁体   English

意外的令牌} onclick事件

[英]Unexpected token } onclick event

I browsed though many "unexpected token", "illegal" etc. topics, one helped me by checking for invisible characters and copying the script to jslint throwed me some missed brackets error, but there are still one problem with this line: 我浏览了许多“意外令牌”,“非法”等主题,其中一个帮助我检查不可见字符并将脚本复制到jslint,这使我错失了一些括号错误,但此行仍然存在一个问题:

JS: JS:

document.getElementById('pois').innerHTML =('<p><label><input type="checkbox" id="01" onclick="toggleGroup("01")" CHECKED/></label>01</p>');

The pois div is located in the html file. pois div位于html文件中。

Alternatively, how would I write the above line with jQuery, as the inline JS is not considered correct? 另外,由于内联JS被认为是不正确的,我该如何用jQuery写上一行? The below function doesn't work as I'd like: 以下功能无法正常运行:

$("#01").click(function() {
    toggleGroup();
});

The corresponding function: 对应功能:

var markerGroups = { "01": [], "02": [] , "03": [] , "04": [] };
function toggleGroup(id_category) {
    for (var i = 0; i < markerGroups[id_category].length; i++) {
    var marker = markerGroups[id_category][i];
    if (marker.getMap()) {
        marker.setMap(null);
    } else {
        marker.setMap(map);
       }
    } 
}

Perhaps you need to change onclick to onchange ? 也许您需要将onclick更改为onchange This will capture the tick box change event. 这将捕获复选框更改事件。 I'm not too sure what the toggleGroup function is doing but this might help. 我不太确定toggleGroup函数在做什么,但这可能会有所帮助。

The error raised because you have missed one bracket } on end of your function 引发的错误,因为你已经错过了一个支架}你的函数结束

function toggleGroup(id_category) {
    for (var i = 0; i < markerGroups[id_category].length; i++) {
    var marker = markerGroups[id_category][i];
    if (marker.getMap()) {
        marker.setMap(null);
    } else {
        marker.setMap(map);
   }
    }
} //<== missing one

http://jsfiddle.net/QF9sN/5/ http://jsfiddle.net/QF9sN/5/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM