JS和Wordpress中未捕获到的SyntaxError [英] Uncaught SyntaxError in JS and possibly Wordpress

查看:84
本文介绍了JS和Wordpress中未捕获到的SyntaxError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太确定为什么我的代码会导致这种情况.

I'm not too sure why my code is causing this.

我的头中有这个jquery脚本:

I have this jquery script in the header:

<script>
  $(document).ready(function() {
      $('.control').on('click', function(e) {
          e.preventDefault();
          var field = $(this).data('field');
          $('.hider:visible').fadeOut("slow", function() {
              $('#' + field + '-gallery, #' + field + '-tag').fadeIn("slow");
          });
      });

      var randomIndex = Math.floor((Math.random() * 100) + 1) % 3;
      console.log(randomIndex);

      var field = $($('a').get(randomIndex)).data('field');
      $('#' + field + '-gallery, #' + field + '-tag').fadeIn("slow");
  })​;
   </script>

当我重新加载页面时,什么也没有发生,因此脚本似乎没有运行.当我在Chrome上检查页面时,我看到此错误出现在名为(程序)的选项卡中,并且在前几行中:

when I reload the page, nothing happens so it appears the script isn't running. When I inspect the page on Chrome, I see there is this error which is in a tab called (program) and it's in the first few lines line:

    if (window.top.require) {
Uncaught SyntaxError: Unexpected token ILLEGAL
    window.top.require("ripple/bootstrap").inject(window, document);}

我不知道导致此错误的代码是什么.当我拿出脚本时,它就消失了.不太确定是wordpress还是jqueryUI(我已经为另一个插件加载了它).

I don't know what it is in my code to cause this error. When I take out my script, it goes away. Not too sure if it's something with wordpress or jqueryUI (I have that loaded for another plugin).

推荐答案

);之间的最后一行,您有一个非法的不可见字符.

You have an illegal invisible character on the last line between the ) and the ;.

将光标置于;之后,并开始退格,直到删除),然后再次键入它们.

Place your cursor after the ;, and start backspacing until you delete the ), then retype them both.

    })​;
 //  ^^---between these

您会注意到,在退格时,光标将无法移动一次.那就是删除不可见字符的时候.

You'll notice that while backspacing, the cursor will fail to move one time. That's when the invisible character is being deleted.

当从jsFiddle或其他类似站点复制/粘贴代码时,就会发生这种情况.

This happens when copy/pasting code from jsFiddle or perhaps other similar sites.

字符是Unicode \u200B.

The character is the unicode \u200B.

这篇关于JS和Wordpress中未捕获到的SyntaxError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆