可以加一个id 或者 直接给个style 我是这样写的setAttribute("style","outline:"+color+" dashed 2px;") 但不知道要怎么 点击按钮时把样式删除。

解决方案 »

  1.   


    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="gb2312" />
    <title></title>
    </head>
    <body>
    <div id="test" style="border:1px solid red;">123</div>
    <button id="btn">click</button>
    <script>
    function $(el){
    return typeof el == 'string' ? document.getElementById(el) : el;
    }
    function $t(name, cot){
    cot = cot || document;
    return cot.getElementsByTagName(name);
    }
    $('btn').onclick = function(){
    $('test').removeAttribute('style');
    }
    </script>
    </body>
    </html>
    这个意思?
      

  2.   

    <span id="demo">DEMO</span>
    <script type="text/javascript">
    document.getElementById('demo').style.outline = '2px dashed red'; //添加
    document.getElementById('demo').style.outline = ''; //删除
      

  3.   

    这样不行哦 。 如果style中有别的样式那不是都给删了吗?
      

  4.   


    <!DOCTYPE HTML>
    <html>
        <head>
            <meta charset="gb2312" />
            <title></title>
        </head>
        <body>
            <div id="test" style="border:1px solid red; color:red; font-size:123px;">123</div>
            <button id="btn">click</button>
            <script>
                function $(el){
                    return typeof el == 'string' ? document.getElementById(el) : el;
                }
    function removeStyle(obj, name){
    if(!name) {
    obj.removeAttribute('style');
    return obj;
    }
    var s = obj.style;
    if(s.removeAttribute){
    s.removeAttribute(name);
    } else {
    name = name.replace(/([A-Z])/g, function(v){
    return '-' + v.toLowerCase();
    });
    s.removeProperty(name);
    }
    return obj;
    }

                $('btn').onclick = function(){
                   removeStyle($('test'), 'fontSize')
                }
            </script>
        </body>
    </html>楼主这个 意思?
    ie下 删除border不友好,
    可以 换成 对class进行操作,类似于addClass removeClass 楼主再看看。
      

  5.   

    calmcrime  在问个问题 <a class="zheng-ze-biao-da-shi ss" href="http://paper.wenweipo.com/2012/05/16/CH1205160004.htm" tag="reg">sdfsdf</a>
      我想把zheng-ze-biao-da-shi ss 中的”zheng-ze-biao-da-shi空格“去掉。一个的我回两个的怎么弄。
      

  6.   

    将className的值 转换为 数组 再操作<!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="gb2312" />
    <title></title>
    </head>
    <body>
    <a class="zheng-ze-biao-da-shi ss" href="#" tag="reg" id="test">sdfsdf</a>
    <script>
    function $(el){
    return typeof el == 'string' ? document.getElementById(el) : el;
    }
    $('test').className = $('test').className.split(' ')[1];
    </script>
    </body>
    </html>