简体   繁体   中英

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:

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样式对象

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM