简体   繁体   English

使用javascript设置webkit值的正确方法

[英]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.barfoo['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.

相关问题 JavaScript:使用名称和默认值设置对象参数的正确方法 - JavaScript: correct way to set object parameters with name and default value 获取/设置Javascript成员的正确方法? (本期使用Kineticjs) - Correct way to get/set Javascript members? (This issue using Kineticjs) 基于Java用户输入,设置Date()对象的正确方法是什么 - what is the correct way to set a Date() object based on user input in Javascript 使用 Javascript 变量设置 Webkit 关键帧值 - Set Webkit Keyframes Values Using Javascript Variable "使用 JavaScript 设置 webkit-keyframes from\/to 参数" - Set the webkit-keyframes from/to parameter with JavaScript ReactJS:将状态值设置为数组的正确方法是什么? - ReactJS: What is the correct way to set a state value as array? 在 JavaScript 中设置默认值的惯用方法 - Idiomatic way to set default value in JavaScript 将元素值添加到Javascript数组末尾的正确方法是什么? - What is the correct way to add an element value to the end of a Javascript array? 如何以正确的方式从用Java隐藏的输入类型中获取价值? - How to get value from input type hidden with Javascript in correct way? 在JavaScript中测试多维数组中值是否存在的正确方法是什么? - What is the correct way to test the existence of a value in a multidimentionnal array in Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM