带引号的Javascript导致Blogger模板中缺少参数 [英] Javascript With Quote Causes Missing Argument In Blogger Template
问题描述
当我使用以下代码时,它可以正常工作:
When I use the following code, it works fine:
<script>
$(document).ready(function() {
$('#article-sidebar-tabbed-archive-gadget').prepend('<nav></nav>');
});
</script>
但是,如果我使用任何类型的引号,都会出现以下错误:
However, if I use any kind of quotes, I get the following error:
参数列表后未捕获到的SyntaxError:缺少
Uncaught SyntaxError: missing ) after argument list
所使用的导致错误的代码示例:
Example of the code used that causes the error:
<script>
$(document).ready(function() {
$('#article-sidebar-tabbed-archive-gadget').prepend('<nav><a href="#">Tags</a></nav>');
});
</script>
是什么原因导致错误,我该如何解决?
What causes the error and how can I fix it?
推荐答案
除非代码位于HTML/JavaScript小部件内或帖子内,否则请尝试以下操作:
Unless the code is inside an HTML/Javascript widget or inside a post, try like this:
<script>
// <![CDATA[
$(document).ready(function() {
$('#article-sidebar-tabbed-archive-gadget').prepend('<nav><a href="#">Tags</a></nav>');
});
// ]]>
</script>
原因是Blogger可以弄乱一些javascript编码,除非您将其包装在CDATA中.有点试验对我来说是一个错误.或者也许您只需要转义所有这样的元素:
The reason is that Blogger has a way to mess some javascript coding unless you wrap it inside the CDATA. A bit of trial an error for me to learn that. Or maybe you just need to escape the all a element like this:
无论如何,我在一个新的博客文章中测试了您的代码,它工作正常.因此,如果我不得不猜测,我提到的解决方案应该可以起作用...
Anyway, I tested you code inside a new blogger post and it works fine. So, if I had to guess, the solutions I mention should work...
这篇关于带引号的Javascript导致Blogger模板中缺少参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!