JavaScript - 未捕获的语法错误:意外标记?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11444427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript - Uncaught SyntaxError: Unexpected token ?
提问by test
What is wrong with this sample code? o_O
这个示例代码有什么问题?o_o
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
console.log("Testing");
$('#test').append("Test");?
});
</script>
<title>Sin título 4</title>
</head>
<body>
<div id="test">Hello world.</div>
</body>
</html>
回答by
You have an illegal invisible character at the end of this line...
你在这一行的末尾有一个非法的隐形字符......
$('#test').append("Test");?// <-- right before this comment
Delete the line entirely, and retype it, or make sure the cursor is after all characters on the line, and hit backspace until you see characters actually being removed.
完全删除该行,然后重新键入,或者确保光标位于该行上的所有字符之后,然后按退格键直到您看到实际删除的字符。
This happens sometimes if you copy & paste code from jsFiddle.
如果您从 jsFiddle 复制和粘贴代码,有时会发生这种情况。
The charCode of the offending character is 8203.
违规字符的 charCode 是 8203。