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
429 views
in Technique[技术] by (71.8m points)

jquery - Javascript - How to Escape Double quotes from Dynamic string content, Unexpected identifier error

Have used to Bind Login User name from portal to a Javascript variable. User name contains either SingleQuote or DiubleQuote sometimes.

My Javascript code failed to read string with DiubleQuote.

EX:

var userName = "Happy and "Care" Ltd"; -  error: unknown: Unexpected token, expected ";"
var userName1 = 'Happy and Care's Ltd'; - error: unknown: Unexpected token, expected ";"
question from:https://stackoverflow.com/questions/65916835/javascript-how-to-escape-double-quotes-from-dynamic-string-content-unexpected

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

1 Answer

0 votes
by (71.8m points)

You can use backticks `` like this :

var userName = `Happy and "Care" Ltd`;
var userName1 = `Happy and Care's Ltd`;

console.log(userName)
console.log(userName1)

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

2.1m questions

2.1m answers

60 comments

56.9k users

...