[英]Correct way to set webkit value with javascript
I can normally use the syntax: 我通常可以使用以下语法:
element.style.styleName = someValue
Such as: 如:
element.style.top = "20px"
But the following bugs because of the "-" 但是以下错误是由于“-”
element.style.-webkit-user-select = "initial"
What is the correct way to handle this? 处理此问题的正确方法是什么?
element.style['-webkit-user-select'] = 'initial';
In JavaScript, foo.bar
and foo['bar']
are equivalent. 在JavaScript中,
foo.bar
和foo['bar']
是等效的。 If the former would cause a syntax error, you can always fall back on the latter. 如果前者会导致语法错误,那么您始终可以依赖后者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.