最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

can't get unicode character to display properly - Javascript and HTML - Stack Overflow

programmeradmin2浏览0评论

I'd like to put a unicode up arrow in an html input button that is being generated in Javascript.

These are the codes for the up arrow from unicode-table:
Unicode number: U+2191
HTML-code: & #8593; (space between the & and # so you can see the code and not the arrow)

I do have
<charset="utf-8" /> in my head tag in the html file.

I've tried every variation of those two codes I can think of within the <> below and all I get in the browser is the text of the codes I've tried.

Here's the line of code:

upButton.setAttribute("value", "<up arrow code here>");

I'd like to put a unicode up arrow in an html input button that is being generated in Javascript.

These are the codes for the up arrow from unicode-table.:
Unicode number: U+2191
HTML-code: & #8593; (space between the & and # so you can see the code and not the arrow)

I do have
<charset="utf-8" /> in my head tag in the html file.

I've tried every variation of those two codes I can think of within the <> below and all I get in the browser is the text of the codes I've tried.

Here's the line of code:

upButton.setAttribute("value", "<up arrow code here>");
Share Improve this question asked Apr 3, 2014 at 4:26 lwaldenlwalden 8037 silver badges11 bronze badges 4
  • If stuff is being treated as HTML, etc, use the code formatting, that's what it's there for. – alex Commented Apr 3, 2014 at 4:28
  • not sure what you mean by that @Alex. It seems if I create the button in the html file it works fine, but create th button in Javascript and it will not. For my purposes I need to create it in Javascript, however. – lwalden Commented Apr 3, 2014 at 4:35
  • possible duplicate of Insert Unicode character into JavaScript – Jukka K. Korpela Commented Apr 3, 2014 at 4:47
  • Try this: '\u{2191}' – Piotr Kowalski Commented Nov 4, 2017 at 22:04
Add a ment  | 

3 Answers 3

Reset to default 5

try this string instead of an html escape character (this is a JavaScript string after all, not an html text node) \u2191'

To escape any symbol in JavaScript, use this tool: http://mothereff.in/js-escapes#1%E2%86%91 For your example, '↑' bees '\u2191'.

To escape any symbol in HTML, use this tool: http://mothereff.in/html-entities#%E2%86%91 For your example, bees &#x2191; or &uarr;.

Try using this in your html: &uparrow;

发布评论

评论列表(0)

  1. 暂无评论