意外的标记 }

pet*_*ter 0 html javascript css

我试图通过使用此代码在我的网页上定位一个地方

<div id="mover" onclick="moveTo(".main", 3);">erer</div>
Run Code Online (Sandbox Code Playgroud)

多数民众赞成我的按钮^^

这是我的功能vv

this.moveTo = function(el5, page_index) {

if (typeof el5 == "string") el5 = document.querySelector(el5);

    var current = document.querySelector(settings.sectionContainer + ".active"),
        next = document.querySelector(settings.sectionContainer + "[data-index='" + (page_index) + "']");

    if(next) {
      var next_index = next.dataset.index;
        _removeClass(current, "active");
        _addClass(next, "active");
        _removeClass(document.querySelector(".onepage-pagination li a" + ".active"), "active");
        _addClass(document.querySelector(".onepage-pagination li a" + "[data-index='" + (page_index) + "']"), "active");

        body.className = body.className.replace(/\bviewing-page-\d.*?\b/g, '');
        _addClass(body, "viewing-page-"+ next_index);

        pos = ((page_index - 1) * 100) * -1;

        if (history.replaceState && settings.updateURL == true) {
            var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (parseInt(page_index) - 1);
            history.pushState( {}, document.title, href );
        }
        _transformPage(el5, settings, pos, page_index, next);
    }
}
Run Code Online (Sandbox Code Playgroud)

我保持得到这个错误,'未捕获语法错误:意外令牌}'并突出显示下面的代码,我无法找到任何错误

<div id="mover" onclick="moveTo(".main", 3);">erer</div>
<div class="container" style="height:70px">
Run Code Online (Sandbox Code Playgroud)

Tao*_*oPR 5

更改函数内的双引号

<div id="mover" onclick="moveTo(".main", 3);">erer</div>
Run Code Online (Sandbox Code Playgroud)

单引号

<div id="mover" onclick="moveTo('.main', 3);">erer</div>
Run Code Online (Sandbox Code Playgroud)

函数内部的双引号与双引号冲突,表示onclick属性的范围.

建议

由于双引号通常在HTML中使用,因此我们应该在大多数情况下使用JavaScript的单引号,这样两者都不会相互冲突.