HTML Entities with jQuery

我们两清 提交于 2019-12-12 14:35:04

问题


I would like to use replace the value of a submit button with Loading….

The problem is that when I click the button I still see … instead of three dots.

Here's my code:

$("#myid").val("Loading…");

Should I enter the ellipsis directly from the keyboard in the code above? Is it safe with UTF-8?


回答1:


val() or value sets a plain text value. … is HTML, not text; you could use it in innerHTML or .html(), but not in a form field value.

If you want to include U+2026 HORIZONTAL ELLIPSIS in a JavaScript string where the encoding is not guaranteed, you could escape it to:

'Loading\u2026'

Should I enter the ellipsis directly from keybord in the code above? Is it safe with UTF-8?

Yes.

However, the ellipsis has a compatibility decomposition into three period characters; it is really only there for backwards compatibility with older character sets. These days the idea is just to use three periods, and let the font deal with coming up with combined glyphs if necessary. In any case, there is little to no visual difference between three periods and an ellipsis in most (proportional) fonts.




回答2:


Just as note, these are the useful spanish characters

\u00E1  á
\u00E9  é
\u00ED  í
\u00F1  ñ
\u00F3  ó
\u00FA  ú

\u00C1  Á
\u00C9  É
\u00CD  Í
\u00D1  Ñ
\u00D3  Ó
\u00DA  Ú

I've created a useful tool to convert whatever you want to the corresponding \uVALUE in JS :) http://jsfiddle.net/tomasdev/VjAkJ/



来源:https://stackoverflow.com/questions/1417818/html-entities-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!