<html>
<head>
<script language="javascript">
function setAttr(n, attr, val) {
if(typeof n == "string") n = document.getElementById(n);
n.setAttribute(attr, val);
}
</script>
</head>
<body>
<ul id="list">
<li>one</li>
<li>three</li>
<li>four</li>
<li>two</li>
</ul>
<p style="color: red">This is a simple document</p>
<input type="button" value="Change Color" onclick="setAttr('list', 'style','color: blue')"/>
</body>
</html>
在firefox2.0下运行正常,在ie6下根本没有效果,那位高手告诉我这是为什么?

解决方案 »

  1.   

    <html>
    <head>
    <script language="javascript">
    function setAttr(n, attr, val) {
    if(typeof n == "string") n = document.getElementById(n);
    n.style.color="blue";
    }
    </script>
    </head>
    <body>
    <ul id="list">
    <li>one</li>
    <li>three</li>
    <li>four</li>
    <li>two</li>
    </ul>
    <p style="color: red">This is a simple document</p>
    <input type="button" value="Change Color" onclick="setAttr('list', 'style','color: blue')"/>
    </body>
    </html>
      

  2.   

    <html>
    <head>
    <script language="javascript">
    function setAttr(n, attr, val) {
    if(typeof n == "string") n = document.getElementById(n);
    if(attr=='style') n.style.cssText = val;
    else n.setAttribute(attr, val);
    }
    </script>
    </head>
    <body>
    <ul id="list">
    <li>one</li>
    <li>three</li>
    <li>four</li>
    <li>two</li>
    </ul>
    <p style="color: red">This is a simple document</p>
    <input type="button" value="Change Color" onclick="setAttr('list', 'style','color: blue')"/>
    </body>
    </html>
      

  3.   

    管理:http://community.csdn.net/expert/Topicview2.asp?id=5618796