首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

想动态设置样式,不知道如何写

2012-03-05 
想动态设置样式,不知道怎么写想动态设置样式,下面这样写不行,请问要怎么写?div idd1 stylefont-weig

想动态设置样式,不知道怎么写
想动态设置样式,下面这样写不行,请问要怎么写?
<div id="d1" style="font-weight:bold"></div>
<script language="javascript">
d1.setAttribute('style', 'font-weight: bold; font-size: 11px');
</script>

[解决办法]
当然不行,style 是对象属性,无法直接设置!
L@_@K

HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>    <title> new document </title>    <meta name="generator" content="editplus" />    <meta name="author" content="Gao YiXiang" />    <meta name="email" content="yixianggao@126.com" />    <meta name="keywords" content="javascript dhtml dom" />    <meta name="description" content="I love web development." /></head><body>    <div id="d1">Dynamic Style</div>     <script   language="javascript">     d1.style.fontWeight = 'bold';     d1.style.fontSize = "20px";    </script> </body></html> 

热点排行