Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
599 views
in Technique[技术] by (71.8m points)

jquery - Put quotes around a variable string in JavaScript

I have a JavaScript variable:

var text = "http://example.com"

Text can be multiple links. How can I put '' around the variable string?

I want the strings to, for example, look like this:

"'http://example.com'"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
var text = ""http://example.com""; 

Whatever your text, to wrap it with ", you need to put them and escape inner ones with . Above will result in:

"http://example.com"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...