问题
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:
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?
回答1:
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>
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...
回答2:
Maybe you just need to escape the double quotes, try this:
<script>
$(document).ready(function() {
$('#article-sidebar-tabbed-archive-gadget').prepend('<nav><a href=\"#\">Tags</a><nav>');
});
</script>
来源:https://stackoverflow.com/questions/57700489/javascript-with-quote-causes-missing-argument-in-blogger-template