In javascript I'm defining some in-line stylings, one of them is font-weight. Unfortunately it doesn't work as automatically 'px' is added at the end of the value and then it doesn't get rendered as the value is not correct :
在javascript中我定义了一些内嵌样式,其中一个是font-weight。不幸的是它不起作用,因为在值的末尾添加了自动'px',然后由于值不正确而不会呈现它:
Note: I'm using react , therefore the code looks like the following.
注意:我正在使用react,因此代码如下所示。
render: function() {
return (
<table>
<tbody>
<tr>
{
data.map(function(d, i) {
var style = {};
if (d.value === 'selected') {
style['color'] = '#FFFFFF';
style['font-size'] = '16px';
style['font-style'] = 'normal';
style['font-weight'] = '700';
style['text-transform'] = 'uppercase';
}else {
style['border'] = '2px solid #C9C9C9';
style['color'] = '#C9C9C9';
style['font-size'] = '12px';
style['font-style'] = 'normal';
style['font-weight'] = '400';
}
return (<td>
<div style={style}>
{d.value}
</div>
</td>);
})
}
</tr>
</tbody>
</table>
);
}
When I inspect it in chrome, it shows : font-weight: 700px
and it doesn't work as px
makes the value incorrect.
当我在chrome中检查它时,它显示:font-weight:700px并且它不起作用,因为px使值不正确。
1 个解决方案
#1
try using style['fontWeight']
instead of style['font-weight']
according to the react documentation here the fontWeight property will not get the automatic 'px' suffix.
尝试使用样式['fontWeight']而不是样式['font-weight']根据此处的反应文档,fontWeight属性将不会获得自动'px'后缀。
#1
try using style['fontWeight']
instead of style['font-weight']
according to the react documentation here the fontWeight property will not get the automatic 'px' suffix.
尝试使用样式['fontWeight']而不是样式['font-weight']根据此处的反应文档,fontWeight属性将不会获得自动'px'后缀。