【问题标题】:Uncaught SyntaxError: Unexpected identifier and unexpected token未捕获的 SyntaxError:意外的标识符和意外的令牌
【发布时间】:2019-03-18 19:39:11
【问题描述】:

我真的不明白为什么我在下面的代码(以粗体显示)中出现两次这个错误(Uncaught SyntaxError: Unexpected identifier),你能帮帮我吗? (我在两个不同的实例中运行它;一个作为函数,另一个作为简单代码以尝试进一步调试,但我真的不明白为什么会同时出现这两个错误)。 我还在 Edge、Firefox 和 Googlechrome 上尝试过。

		function CheckUrlParams(){
			//Get the URL as String
			var **sPageURL = window.location.search.substring(1);**
			console.log(sPageURL);
			//Split the URL string into an array
			var sURLVariables = sPageURL.split("&");
			console.log(sURLVariables);
			for (var i = 0; i < sURLVariables.length; i++){
				var sParameterName = sURLVariables[i].split("=");
				console.log(sParameterName);
				if (sParameterName[0] == "WMV"){
					console.log(sParameterName);
					return sParameterName[1];
				}
			}
		**}​**

【问题讨论】:

  • 如果从函数的第一行开始出现错误,则问题可能出在函数定义未正确关闭之前。
  • 末尾的} 后面有一个非打印Unicode 字符。代码点 0x5396b。
  • 好吧,我的测试中除了这个功能之外别无他法。实际上,我首先将它单独放置,然后将其包装在 $(document).ready(Function({ [My testing function] }); 因为函数的关闭 } 出现错误
  • 如果您注意删除 ** 字符以及 } 之后的任何内容,则没有语法错误 - 放置一个 ;在最后一个}之后
  • 谢谢,“sPageURL = window.location.search.substring(1);”怎么样?怎么了 ?有什么想法吗?

标签: jquery syntax-error unexpected-token


【解决方案1】:

由@Barmar 发现:末尾的 } 后面有一个非打印的 Unicode 字符。代码点 0x5396b

第二个问题已经通过移除窗口解决了,这并没有真正影响功能的效果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 2013-09-19
    • 2016-10-23
    相关资源
    最近更新 更多