$('#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"> \
但是,我没有看到任何奇怪的东西。
答案 0 :(得分:1)
由于您分割多行字符串的方式,浏览器很可能在每个\
插入行尾字符,而jQuery可能不喜欢这些字符。只是研究你的问题,我看到的几乎所有文章都建议不要使用这种类型的线分割。相反,你可以做几件事:
编辑:您错过了\
行的<p>
。不过,我仍会考虑以下其中一项更改。
只需使用常规字符串连接:
$('#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>'
);
使用模板:
<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());