意外的令牌错误

时间:2015-08-03 18:27:24

标签: javascript html

我在下面的脚本上收到错误。它说Uncaught SyntaxError: Unexpected token :

我不确定为什么会这样或者我缺少什么

        <script> //[CDATA[
if (%%GLOBAL_Availability%% == "") {'error is here
    document.getElementById("ShopButton").style.display = "block";
    document.querySelector("#ShopButton").addEventListener("click",function(){
      window.location.href='%%GLOBAL_Availability%%';
    },false);
}
    //]]> </script>

以下是它在Chrome上的显示方式:

enter image description here

感谢任何帮助

1 个答案:

答案 0 :(得分:1)

错误是因为您没有将%%GLOBAL_Availability%%放在引号内。

if ('%%GLOBAL_Availability%%' == "") {
    document.getElementById("ShopButton").style.display = "block";
    document.querySelector("#ShopButton").addEventListener("click",function(){
      window.location.href='%%GLOBAL_Availability%%';
    },false);
}

我不确定%%GLOBAL_Availability%%你的意思。它不是有效的变量名称,也不是有效的URL。

  

变量名必须以$,_或Unicode类别中的任何字符开头“大写字母(Lu)”,“小写字母(Ll)”,“标题字母(Lt)”,“修饰符字母(Lm)” “,”其他字母(Lo)“或”字母编号(Nl)“。

     

字符串的其余部分可以包含相同的字符,以及任何U + 200C零宽度非连接字符,U + 200D零宽度连接字符和Unicode类别中的字符“非间距标记(Mn)”, “间距组合标记(Mc)”,“十进制数字编号(Nd)”或“连接符标点符号(Pc)”。