简体   繁体   中英

JQuery: How to text insert HTML ascii character?

I have the following JQuery code:

$(this).text('Options ▴');

However, the ascii code isn't showing up on my web page. All that shows up is on the webpage is Options ▴ .

What am I doing wrong?

Use the .html() method instead of .text() .

The whole point of .text() method is to make the text appear exactly as it's in the string, with all tags and entities.

If you use a unicode escape ('\▲') instead of the html escape character, you can use the .text method.

Some users will not have a font that will display either version.

&#x25B4 is definitely not ascii (ascii's a character code that runs from 0 to 127...!-) -- it seems to be a high-page unicode character. What char encoding is your page using? With something "universal" like utf-8, unicode characters should show up... if the browser has them in its font, of course. With other encodings, such characters might just be impossible to transmit and show.

..or if someone wants to use just javascript:

var d = document.createElement("div");
d.appendChild(document.createTextNode("500"));
var euro = document.createElement("span");
euro.innerHTML = "€"; //your character
d.appendChild(euro);

prints: 500€

You can try this:

$(this).html('Options ▴');

Output:

Options ▴

If you want to test it online you can check out this website . (I liked it very much)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM