jquery中有单双引号怎么赋值给一个变量

jquery中有单双引号怎么赋值给一个变量,第1张

<input type="button" onclick="alert("1")">-------------------不正确

<input type="button" onclick="alert('1')">-------------------正确

单双引号赋值的时候,需要在前面加上反义符号\。

例子如下:

var str = "abc\"def\'ghi"
str被赋值为abc"def'ghi

Private Sub Command1_Click()
Dim a As Integer
a = 100
Shell "cmd /c" & "shutdown -s -t " & a
End Sub
注意:其中的 -和s、-和t中间不能有空格。

js语言没有这个功能的,只能自定义一个类似的方法:

Stringprototypeformat=function(o){
    return thisreplace(/\$\{([^\}]+)\}/g,function(m,key){
        return o[key]||''
    });
}
consolelog('test${str}-${str}'format({str:'abc'}))

类似这样的去实现,不过正如你看到的,依然不够方便


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13383030.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-25
下一篇 2023-07-25

发表评论

登录后才能评论

评论列表(0条)

保存