re1*_*man 26 javascript string jquery
我有一个JavaScript变量:
var text = "http://example.com"
Run Code Online (Sandbox Code Playgroud)
文字可以是多个链接.如何在变量字符串周围加上''?
我希望字符串,例如,看起来像这样:
"'http://example.com'"
Run Code Online (Sandbox Code Playgroud)
Sar*_*raz 46
var text = "\"http://example.com\"";
Run Code Online (Sandbox Code Playgroud)
无论你的文字是什么,用它来包装",你需要把它们放在里面然后用它来逃避\.以上将导致:
"http://example.com"
Run Code Online (Sandbox Code Playgroud)
Aja*_*jai 23
var text = "http://example.com";
text = "'"+text+"'";
Run Code Online (Sandbox Code Playgroud)
将单引号(')附加到字符串的前面和后面.
小智 6
您可以使用模板文字添加这些单引号:
var text = "http://example.com"
var quoteText = `'${text}'`
console.log(quoteText)Run Code Online (Sandbox Code Playgroud)
在JavaScript中表示以下文本:
"'http://example.com'"
Run Code Online (Sandbox Code Playgroud)
使用:
"\"'http://example.com'\""
Run Code Online (Sandbox Code Playgroud)
要么:
'"\'http://example.com\'"'
Run Code Online (Sandbox Code Playgroud)
请注意:我们总是需要使用\来转义包围字符串的引号。
JS小提琴:http://jsfiddle.net/efcwG/
一般指针:
例
var answer="It's alright";
var answer="He is called 'Johnny'";
var answer='He is called "Johnny"';
Run Code Online (Sandbox Code Playgroud)
例
var answer='It\'s alright';
var answer="He is called \"Johnny\"";
Run Code Online (Sandbox Code Playgroud)
http://www.w3schools.com/js/js_obj_string.asp
小智 5
我认为,对您来说,将价值放在报价内的最佳简便方法是:
JSON.stringify(variable or value)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
125530 次 |
| 最近记录: |