[英]How to edit CSS styles in JavaScript?
So for example I can do this: 因此,例如,我可以这样做:
document.getElementById('element').onclick = function() {
document.getElementById('element').style.color = '#FFFFFF';
}
But how should I do this? 但是我应该怎么做呢?
document.getElementById('element').onclick = function() {
document.getElementById('element').style.-moz-box-shadow = '1px 1px 1px #000';
}
I hope you get what I mean :) 我希望你明白我的意思:)
Please do not post any answer related with jQuery or any library, I want it in plain javascript. 请不要发布与jQuery或任何库相关的任何答案,我希望使用纯JavaScript。
I believe it's: 我相信是:
myobject.MozBoxShadow = '1px 1px 1px #000';
It doesn't follow the "typical" formatting of a style object (which would lower-case the "M") because of the initial "-" character. 由于初始的“-”字符,它不遵循样式对象的“典型”格式(会小写“ M”)。 Converting between style properties and JS properties for those styles means: 在这些样式的样式属性和JS属性之间进行转换意味着:
Thus, "-moz-box-shadow" becomes: 因此,“-moz-box-shadow”变为:
I think you change '-' to a capital letter, so: 我认为您将“-”更改为大写字母,因此:
document.getElementById('element').style.-moz-box-shadow = 1px 1px 1px #000;
Should be: 应该:
document.getElementById('element').style.MozBoxShadow = "1px 1px 1px #000";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.