[英]Escaping automatic encoding of & character in JavaScript
I want to create a form button whose input value is a font icon. 我想创建一个表单按钮,其输入值为字体图标。 FontAwesome in this case.
FontAwesome在这种情况下。 So I use a entity such as this for the input value:

因此,我将这样的实体用作输入值:

In plain HTML styled in CSS with font-family: FontAwesome
, everything works as expected: 在CSS中以
font-family: FontAwesome
样式化的纯HTML中,一切都按预期工作:
<input type="submit" class="btn fa-input" value=" Input">
However, I want to create this element using JavaScript. 但是,我想使用JavaScript创建此元素。 In that case the & character seems always to end up being encoded so my entity comes out as 
在这种情况下,&字符似乎总是最终被编码,因此我的实体显示为&#xf107;。 Needles to say, that prints out literally instead of the font icon.
需要说的是,它是按原样打印出来的,而不是字体图标。 How do manage to not have that & character encoded?
如何设法不对字符进行编码?
Below is the Javascript I am using 以下是我正在使用的Javascript
var button = utility.dom.createElement('input', {
'type': 'button',
'className': 'fonticon',
'value': '',
'title': 'bla bla bla',
'tabIndex': 1000
});
and the CSS 和CSS
.fonticon {
font-family:FontAwesome;
}
If you are setting the value using JavaScript instead of hardcoding it into your HTML, use a JavaScript escape sequence instead, such as \
. 如果要使用JavaScript设置值,而不是将其硬编码到HTML中,请改用JavaScript转义序列,例如
\
。 Your code for the button's value should change to: 您的按钮值代码应更改为:
'value': '\uf107',
By the way, U+F107 doesn't appear to be a valid character: http://www.fileformat.info/info/unicode/char/f107/index.htm 顺便说一句,U + F107似乎不是有效字符: http : //www.fileformat.info/info/unicode/char/f107/index.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.