jQuery 在 html 中使用 "×" 单词更改为 ×
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16834320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using "×" word in html changes to ×
提问by Mathi
I am using the following code.
我正在使用以下代码。
HTML Code :
HTML代码:
<div class="test">×</div>
Javascript:
Javascript:
alert($(".test").html());
I am getting ×
in alert. I need to get ×
as result.
Anybody knows or faces this problem? Please update your suggestions.
我开始×
警觉了。我需要得到×
结果。
有人知道或面临这个问题吗?请更新您的建议。
采纳答案by Strille
You need to escape:
你需要逃脱:
<div class="test">&times</div>
And then read the value using text()to get the unescapedvalue:
然后使用text()读取值以获取未转义的值:
alert($(".test").text()); // outputs: ×
回答by RichieHindle
You need to escape the ampersand:
你需要逃避&符号:
<div class="test">&times</div>
×
means a multiplication sign. (Technically it should be ×
but lenient browsers let you omit the ;
.)
×
表示乘号。(从技术上讲应该是,×
但宽松的浏览器允许您省略;
.)
回答by Ryan de Vries
回答by Ashik Jyothi
×
stands for ×
in html.
Use &times
to get ×
×
×
在 html 中代表。使用 &times
得到与时代