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 Op开发者_如何学Pythontions ▴
.
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 ('\u25B2') instead of the html escape character, you can use the .text method.
Some users will not have a font that will display either version.
▴
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)
精彩评论