我如何避免单引号? [英] How do I escape a single quote?
本文介绍了我如何避免单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在JavaScript中转义'
(单引号)?
这就是我尝试使用它:
< input type ='text'id ='abc'value ='hel'lo'> ;
以上代码的结果是在文本框中填入hel。
< input type ='text'我试图用'\\'替换'',但这是我得到的。 id ='abc'value ='hel \'lo'>
以上代码的结果是在文本框中填入hel \。
如何成功地转义单引号?
解决方案
实体:
-
&#39;
'
-
&#34;
- ...
更多信息,请参阅 HTML中的字符实体引用 。
How can I escape a '
(single quote) in JavaScript?
This is where I'm trying to use it:
<input type='text' id='abc' value='hel'lo'>
The result for the above code is "hel" populated in the text box. I tried to replace ' with \', but this what I'm getting.
<input type='text' id='abc' value='hel\'lo'>
The result for the above code is "hel\" populated in the text box.
How can I successfully escape the single quotes?
解决方案
You could use HTML entities:
'
for'
"
for"
- ...
For more, you can take a look at Character entity references in HTML.
这篇关于我如何避免单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文