未捕获的语法错误:jQuery 字符串中意外的标记 ILLEGAL

Uncaught SyntaxError: Unexpected token ILLEGAL in jQuery string

本文关键字:意外 字符串 ILLEGAL 语法 错误 jQuery      更新时间:2023-09-26
  $('#post-2233 > h2').text('Feeds / Downloads');
  $('#post-2233 > h2').after(
    '<div class="clo-column-before"> '
       <p>Please login on the right to access the content below.</p> '
       <p>Below is all the downloadable content on the website. Your account gives you access to all the items with a check mark next to it. </p> '
       <p>You can purchase additional access from your <a href="http://www.chineselearnonline.com/amember/member.php">member page</a>. If you have any problems accessing any of the content below, please <a href="http://www.chineselearnonline.com/contact-us/">contact us</a>.</p> '
     </div>'
  );
  $('#post-2233 > .entrytext').after(
    '<div class="clo-column-after"> '
       <h2>Download instructions: PC / Mac, iPhone / iPad, Android</h2> '
       <h3>PC / Mac:</h3> '
       <p>Click directly on the links to open the content. You can then download it directly from the page that opens.</p> '
       <p>Click on the iTunes logo to open the content into iTunes.</p> '
       <p>Note that the PDFs are in a zip archive that will need to extracted after download.</p>
     </div>'
  );
});

这是有问题的行:

<div class="clo-column-after"> '

不过,我没有看到任何奇怪的东西。

由于拆分多行字符串的方式,您的浏览器很可能在每个'插入行尾字符,也许 jQuery 不喜欢这些字符。只是研究你的问题,我看到的几乎每篇文章都建议不要这种类型的分行。相反,您可以做几件事:

编辑:您在最后一行缺少<p> '。但是,我仍然会考虑以下更改之一。

  1. 只需使用常规字符串连接:

    $('#post-2233 > .entrytext').after(
        '<div class="clo-column-after">' +
           '<h2>Download instructions: PC / Mac, iPhone / iPad, Android</h2>' +
           '<h3>PC / Mac:</h3>' +
           '<p>Click directly on the links to open the content. You can then download it directly from the page that opens.</p>' +
           '<p>Click on the iTunes logo to open the content into iTunes.</p>' +
           '<p>Note that the PDFs are in a zip archive that will need to extracted after download.</p>' +
         '</div>'
     );
    
  2. 使用模板:

    <script id="dl-instructions" type="text/template">
        <div class="clo-column-after">
           <h2>Download instructions: PC / Mac, iPhone / iPad, Android</h2>
           <h3>PC / Mac:</h3>
           <p>Click directly on the links to open the content. You can then download it directly from the page that opens.</p>
           <p>Click on the iTunes logo to open the content into iTunes.</p>
           <p>Note that the PDFs are in a zip archive that will need to extracted after download.</p>
         </div>
    </script>
    

    然后你的 jQuery after()调用变为:

    $('#post-2233 > .entrytext').after($('#dl-instructions').html());