未捕获的SyntaxError:无效或意外的令牌 [英] Uncaught SyntaxError: Invalid or unexpected token
本文介绍了未捕获的SyntaxError:无效或意外的令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的剃刀语法:
foreach(var item in model)
{
<td><a href ="#" onclick="Getinfo(@item.email);" >6/16/2016 2:02:29 AM</a> </td>
}
我收到请求的javascript如下:
My javascript that recieves the request goes like this:
<script type="text/javascript" src="~/Scripts/jquery-1.9.1.js"></script>
<script type="text/javascript">
function Getinfo(elem) {
var email = document.getElementById(elem).innerHTML;
}
</script>
点击href链接时,我在浏览器的控制台中收到以下错误:
When clicking on the href link, I get the following error in the console of the browser:
未捕获的SyntaxError:无效或意外的令牌,
"Uncaught SyntaxError: Invalid or unexpected token",
此部分带有下划线:
**</a> </td>**
我是初学者,所以我的语法很多。如果那就是请帮助我。
I am a beginner so I get stuck in syntax a lot. If it is that then please help me out.
推荐答案
你应该传递 @ item.email 引号中的code>然后它将被视为字符串参数
You should pass @item.email
in quotes then it will be treated as string argument
<td><a href ="#" onclick="Getinfo('@item.email');" >6/16/2016 2:02:29 AM</a> </td>
否则,它被视为变量,因此会产生错误。
Otherwise, it is treated as variable thus error is generated.
这篇关于未捕获的SyntaxError:无效或意外的令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文