简体   繁体   English

如何在JavaScript中使用单引号和双引号

[英]How to use single and Double quote in javascript

$("<button class='btn btn-success' onclick='commentupload("+foo.id+","+uname+","+name+")' style='margin-top:5px;align:left'>")

This the code of jquery which i am using to generate this button dynamically. 这是我用来动态生成此按钮的jquery的代码。 i need to pass the 3 argument 1st one is integer so there is no problem with that but the 2nd and the third parameter contains string so it requires ' before and after. 我需要传递3个参数,第一个是整数,因此没有问题,但是第二个和第三个参数包含字符串,因此它需要在'之前和之后'。 But i am unable to implement that. 但是我无法实现。

Please help me with this... 请在这件事上给予我帮助...

您需要转义报价。

$("<button class='btn btn-success' onclick='commentupload(" + foo.id + ", \"" + uname + "\", \"" + name + "\")' style='margin-top:5px; align:left;'>")

您可以使用它来处理它。

$("<button class='btn btn-success' onclick='commentupload(" + foo.id + ", \\"" + uname + "\\", \\"" + name + "\\")' style='margin-top:5px; align:left;'>")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM