HTML实体与jQuery [英] HTML Entities with jQuery

查看:95
本文介绍了HTML实体与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 Loading& hellip; 替换提交按钮的值。



问题是当我点击按钮时,我仍然看到& hellip; 而不是三个点。



这是我的code:

  $(#myid)。val(Loading& hellip;); 

我应该直接从键盘输入上面代码中的省略号吗?用UTF-8安全吗?

解决方案

val() value 设置纯文本值。 & hellip; 是HTML,而不是文本;你可以在 innerHTML .html()中使用它,但不能使用表单字段值。



如果你想在编码不被保证的JavaScript字符串中包含U + 2026 HORIZONTAL ELLIPSIS,你可以将它转义为:

 'Loading\\\…'




我应该直接从keybord在上面的代码中输入省略号吗?使用UTF-8安全吗?


是的。然而,省略号可以分解成三个句点字符;它只是为了向后兼容旧字符集而存在。现在这个想法只是使用三个阶段,如果需要的话,让字体处理混合字形。无论如何,三个阶段之间几乎没有视觉差异,大多数(比例)字体中都有省略号。


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?

解决方案

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.

这篇关于HTML实体与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆