javascript AngularJS 和 HTML:在 onclick 函数的变量中转义引号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20525078/
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
AngularJS and HTML: Escaping quotes inside a variable for an onclick function
提问by Growlithe
i'm just wondering how to escape a function if it has quotes inside. for example, my variable is:
我只是想知道如果函数内部有引号,如何对其进行转义。例如,我的变量是:
{{ video.Id }} = "Don't";
then if my markup in html is like this:
那么如果我在 html 中的标记是这样的:
<button ng-click="executeFunc('{{video.Id}}')"/>
I will have an error saying that I have unterminated quotes. (Coming from the variable that have quotes inside.) Any help would be appreciated! thank you
我会有一个错误,说我有未终止的引号。(来自内部有引号的变量。)任何帮助将不胜感激!谢谢
回答by Jonathan Rowny
You don't need the inner {{}}, just do <button ng-click="executeFunc(video.Id)"/>
您不需要内部 {{}},只需执行 <button ng-click="executeFunc(video.Id)"/>
Your controller function, executeFunc
will get the proper value.
您的控制器功能executeFunc
将获得正确的值。