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?
但它不起作用。有谁知道为什么?
3 个解决方案
#1
8
you can separate
你可以分开
document.getElementById(obj).style.fontWeight='bold';
document.getElementById(obj).style.color='#333';
#2
6
You need to set the underlying cssText
of the style as folows:
您需要将样式的基础cssText设置为folows:
document.getElementById('xx').style.cssText='font-weight:bold; color:#333;';
#3
0
Document's style property is a object, please reference HTML DOM Style Object on W3school
Document的style属性是一个对象,请在W3school上引用HTML DOM Style Object
#1
8
you can separate
你可以分开
document.getElementById(obj).style.fontWeight='bold';
document.getElementById(obj).style.color='#333';
#2
6
You need to set the underlying cssText
of the style as folows:
您需要将样式的基础cssText设置为folows:
document.getElementById('xx').style.cssText='font-weight:bold; color:#333;';
#3
0
Document's style property is a object, please reference HTML DOM Style Object on W3school
Document的style属性是一个对象,请在W3school上引用HTML DOM Style Object