[英]Why doesn't the following Javascript code (to set CSS style) work?
I'm trying to set the CSS style of an object with the following: 我正在尝试通过以下方式设置对象的CSS样式:
document.getElementById(obj).style='font-weight:bold; color:#333;';
but it's not working. 但它不起作用。 Does anyone have any idea why?
有谁知道为什么吗?
you can separate 你可以分开
document.getElementById(obj).style.fontWeight='bold';
document.getElementById(obj).style.color='#333';
您需要将样式的基础cssText
设置为以下内容:
document.getElementById('xx').style.cssText='font-weight:bold; color:#333;';
文档的样式属性是一个对象,请在W3school上参考HTML DOM样式对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.