我想要将一串指定ASCII代码的html实体(即:a)转换为它们所代表的ASCII字符(即:a).我正在使用对象的属性并尝试分配值.例如:
object.Text("");
Run Code Online (Sandbox Code Playgroud)
当我传递的是表示实体的字符串时,我得到相同的字符串.我找不到将实体转换为它们所代表的字符的功能.
Ate*_*ral 20
要将字符串中的所有数字字符实体转换为其等效字符,您可以执行以下操作:
str.replace(/&#(\d+);/g, function (m, n) { return String.fromCharCode(n); })
Run Code Online (Sandbox Code Playgroud)
Jos*_*ola 11
尝试使用String.fromCharCode()函数.
alert(String.fromCharCode(97));
Run Code Online (Sandbox Code Playgroud)
如你所见,你将不得不去掉&符号和英镑符号.
最好的祝福...
归档时间: |
|
查看次数: |
16309 次 |
最近记录: |