44

I am using the following code.

HTML Code :

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

Javascript:

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

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

4

5 回答 5

73

You need to escape the ampersand:

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

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

于 2013-05-30T10:57:30.347 回答
40

You need to escape:

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

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

alert($(".test").text()); // outputs: &times
于 2013-05-30T10:59:03.150 回答
5

I suspect you did not know that there are different & escapes in HTML. The W3C you can see the codes. &times means × in HTML code. Use &amp;times instead.

于 2013-05-30T10:58:21.067 回答
5

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

于 2017-02-06T07:11:22.050 回答
5

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

Use: &#215 with ;

This link provides some additional information about the topic.

于 2017-02-25T16:55:26.520 回答