javascript 如何解决“标识符在数字文字后立即开始”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25509317/
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
How to solve "identifier starts immediately after numeric literal"
提问by chaya
I have tried for following code in javascript, but I get:
我曾尝试在 javascript 中使用以下代码,但我得到:
identifier starts immediately after numeric literal
erroris coming for following script, example mcnDel="016160A1"
以下脚本将出现错误,例如mcnDel="016160A1"
<script>
mcnDel="016160A1"
var val="<a href='javascript: void(0);' onclick='removeRow("+mcnDel+");'><img src=images/delete.png></a></a></td>"
</script>
回答by epascarello
You need to wrap the string with quotes.
您需要用引号将字符串括起来。
onclick='removeRow("+mcnDel+");'
needs to be
需要是
onclick='removeRow(\""+mcnDel+"\");'
回答by Amir
Dont forget Javascript id cannot start with a number, make sure the value of your variable is not starting with a number.
不要忘记 Javascript id 不能以数字开头,请确保变量的值不是以数字开头。
回答by mahdi moghimi
I hope this answer maybe help another : when we want to concat or add something with a string in Js we must use single quotation. for example we have :
我希望这个答案可能对另一个人有所帮助:当我们想在 Js 中连接或添加带有字符串的内容时,我们必须使用单引号。例如我们有:
alert(@ViewBag.IsSecondStepAccepted) === error :identifier starts immediately after numeric literal
but if I use
但如果我使用
alert('@ViewBag.IsSecondStepAccepted')
everything is OK.
一切都好。