当然不行,style 是对象属性,无法直接设置!
L@_@K
<!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="[email protected]" />
    <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>

解决方案 »

  1.   

    font-weight 也没起作用,
    那是标记中 style="font-weight:bold" 起滴作用!
      

  2.   

    解释:font-size为只读,你改变的样式中不能包含这样的值,像backgroundColor这样的值为可读可写。请给分,谢谢
      

  3.   

    fontWeight 我也知道啊
    只是想问看看能不能用什么方法直接 style='font-weight:bold;font-size:11px'
      

  4.   

    To iori_wen事实胜于瞎讲,哈
    L@_@K
    <!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="[email protected]" />
        <meta name="keywords" content="javascript dhtml dom" />
        <meta name="description" content="I love web development." />
    </head>
    <body>
    <DIV STYLE="font-size:12pt" onmouseover="this.style.fontSize='20pt'" onmouseout="this.style.fontSize='12pt'">
    鼠标移过,字体大小动态变换!
    </DIV>
    </body>
    </html>
      

  5.   

    document.getElementById("d1").setAttribute.style.font-weight="bold"; 
      

  6.   

    我自己想到办法了
    用 prototype.js 的 camelize()
    把 font-size 转成 fontSize
    然后 Object.extend(d1.style ,{'style集合'})
    我自己先去试试,回头再来结贴  :D
      

  7.   

    To awuZhang 当然不行,style 是对象属性,无法直接设置!不过你可以只考虑修改样式名或替换.css文件!给个修改样式名滴例子!<!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="[email protected]" />
        <meta name="keywords" content="javascript dhtml dom" />
        <meta name="description" content="I love web development." />
        <style type="text/css">
    .divStyle1
    {
        font-size:12pt;
    }
    .divStyle2
    {
        font-size:20pt;
        font-weight: bold;
        color: red;
    }
        </style>
    </head>
    <body>
    <DIV class='divStyle1' onmouseover="this.className='divStyle2';" onmouseout="this.className='divStyle1';">
    鼠标移过,字体大小动态变换!
    </DIV>
    </body>
    </html>
      

  8.   

    自己写了个方法if('style' in param){
        var s = param['style'];
        var atts = {};
        arr = s.split(";");
        arr.each( function(e){
            att = e.split(":");
            atts[att[0].strip().camelize()] = att[1].strip();
        })
        Object.extend(returnElement.style, atts);
    }