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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:53:04  来源:igfitidea点击:

Using "&times" word in html changes to ×

javascriptjqueryhtml

提问by Mathi

I am using the following code.

我正在使用以下代码。

HTML Code :

HTML代码:

<div class="test">&times</div>

Javascript:

Javascript:

alert($(".test").html());

I am getting ×in alert. I need to get &timesas result.
Anybody knows or faces this problem? Please update your suggestions.

我开始×警觉了。我需要得到&times结果。
有人知道或面临这个问题吗?请更新您的建议。

采纳答案by Strille

You need to escape:

你需要逃脱:

<div class="test">&amp;times</div>

And then read the value using text()to get the unescapedvalue:

然后使用text()读取值以获取未转义的值:

alert($(".test").text()); // outputs: &times

回答by RichieHindle

You need to escape the ampersand:

你需要逃避&符号:

<div class="test">&amp;times</div>

&timesmeans a multiplication sign. (Technically it should be &times;but lenient browsers let you omit the ;.)

&times表示乘号。(从技术上讲应该是,&times;但宽松的浏览器允许您省略;.)

回答by Ryan de Vries

I suspect you did not know that there are different &escapes in HTML. The W3Cyou can see the codes. &timesmeans ×in HTML code. Use &amp;timesinstead.

我怀疑你不知道&HTML 中有不同的转义。W3C你可以看到代码。&times表示×在 HTML 代码中。使用&amp;times来代替。

回答by Ashik Jyothi

&times;stands for ×in html. Use &amp;timesto get &times

&times;×在 html 中代表。使用 &amp;times得到与时代

回答by M. Nashath

Use the &#215code instead of &timesBecause JSF don't understand the &times;code.

&#215代码代替&times因为JSF不懂&times;代码。

Use: &#215with ;

使用:&#215;

This linkprovides some additional information about the topic.

此链接提供了有关该主题的一些附加信息。