Wordpress jQuery Uncaught SyntaxError:意外的令牌ILLEGAL

Ren*_*ary 1 wordpress jquery syntax-error

我准备好试着调试这段代码.我有一个页面需要在同一页面中显示多个子帖子而不会转到另一个页面,但是我无法让代码工作但我找不到任何错误.我甚至完全删除了它并从头开始重新编写它以试图找到错误但没有任何东西,因为javascript总是指向我错误.我试过firebug,jslint并在jsfiddle中做了相同的结构,但我找不到问题.我会说同样的代码在jsfiddle中工作得很好但是没有其他地方.我看到页面正在正确加载jquery所以api不是问题.请帮忙,我不知道还能做什么!

这是代码结构:

HTML-Post Nav

<ul id="sub_select">
  <li class="select">
   <a href="#post1">Post 1</a>
  </li>
  <li class="select">
   <a href="#post2">Post 2</a>
  </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

HTML的帖子

<div id="post1" class="about_txt">
  <div class="title">
    <h1>Post 1</h1>
  </div>
  <div class="desc">
    <p>The post itself</p>
  </div>
</div>
<div id="post2" class="about_txt" style="display: none;">
  <div class="title">
    <h1>Post 2</h1>
  </div>
  <div class="desc">
    <p>The post itself</p>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

jQuery脚本:(

$(document).ready(function() {
    $(".select a").click(function(event){
        event.preventDefault();
        $(".about_txt").hide('slow');
        var toShow = $(this).attr('href');
        $(toShow).show('slow');
    });?
});
Run Code Online (Sandbox Code Playgroud)

更新:我已经添加了我显然忘记复制的$,但感谢您指出这一点.我仍然有这个问题.

Ewy*_*ato 6

在此代码的末尾似乎有一个"不可见"字符:

$(".select a").click(function(event){
    event.preventDefault();
    $(".about_txt").hide('slow');
    var toShow = $(this).attr('href');
    $(toShow).show('slow');
});?  //<= There's an invisible character here, 
     //    you can try pressing backspace once at the end of the semicolon
Run Code Online (Sandbox Code Playgroud)

要快速修复,请删除不可见的字符或复制并粘贴以下代码并替换您的代码:

$(document).ready(function() {
    $(".select a").click(function(event){
        event.preventDefault();
        $(".about_txt").hide('slow');
        var toShow = $(this).attr('href');
        $(toShow).show('slow');
    });
});
Run Code Online (Sandbox Code Playgroud)

编辑:一些调查显示隐形字符为零宽度空间(U + 200B)