行不行先不说,这样做肯定不合理, 嫌长可以用className就是在样式表里定义个class, 多长就都无所谓了
比如
<style>
  .hid {visibility:hidden}
  .vis {visibility:visible}
</style>function(){
  form1.pp.className = hid;
}

解决方案 »

  1.   

    eval也比较浪费资源,像你这种情况完全可以避免的...
      

  2.   

    动态去设置className是个很好的办法,不过我们还可以这样:http://www.scriptlover.com<!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> javascript操作css </title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <style type="text/css">
    .hd {
        height:200px;
        background-color:#33CC66;
    }
    </style>
    <script type="text/javascript">/*****************javascript操作css****************
    writer:tantaiyizu
    date:2008-5-6
    msn:[email protected]
    ********************************************/var css = {
        CName: function(name){
            var _name = name.replace(/-[A-Za-z]/ ,function(rc){    //去掉-并转换-后的字符为大写
                return rc.toUpperCase().replace("-" ,"");
            });
            return _name;
        },
        get: function(elem ,name){        var _name = this.CName(name);    //_name为IE下属性的名字        if(elem.currentStyle){    //IE方式获取
                return elem.currentStyle[_name];
            }
            else if(document.defaultView && document.defaultView.getComputedStyle){    //w3c方式获取
                var s = document.defaultView.getComputedStyle(elem, "");
                return s?s.getPropertyValue(name) : "";
            }        return "";
        },
        set: function(elem ,arg ,value){        if(typeof arg == "string" && typeof value == "string"){    //传入属性,属性值
                arg = this.CName(arg);
                elem.style[arg] = value;
            }
            else if(typeof arg == "object"){ //传入json对象,批量设置
                for(var ii in arg){
                    var _ii = this.CName(ii);
                    elem.style[_ii] = arg[ii];
                }
            }
        }
    };window.onload = function(){
        var d = document.getElementById("kp");
        var x = css.get(d ,"background-color");
        //alert(x)
        //css.set(d ,"background-color" ,"#BFD9FF");
        css.set(d ,{
            "background-color":"#BFD9FF" ,
            "height":"300px"
        });
    };
    </script>
    </head>
    <body>
        <div id="kp" class="hd">
            <pre>
                style="height:100px;background:#33CC66;"
                style="height:100px;background:#33CC66;"
                style="height:100px;background:#33CC66;"
            </pre>
        </div>
    </body>
    </html>
      

  3.   

    function r(o,t){
       o.style.visibility=t?'hidden':'visible';

    r(form1.pp)
    r(form1.pp,1)
    当然在函数里直接用样式也可以。
      

  4.   

    谢谢myvicy。不好意思,好结贴。没办给你加分。