这个用 jQuery 最方便了,直接 $('span') 即可获取所有的 span 元素。
参考:
http://download.csdn.net/detail/defonds/4125256

解决方案 »

  1.   

    是要通过attr(),来获取属性吗?
      

  2.   

    用Jquery,这个是隐藏所有<p>的例子,改改就行了
    <html>
    <head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    $("button").click(function(){
    $("p").hide();
    });
    });
    </script>
    </head><body>
    <h2>This is a heading</h2>
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
    <button type="button">Click me</button>
    </body>
    </html> 
      

  3.   

    <!DOCTYPE html>
    <html>
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
    </script>
    <script>
    $(document).ready(function(){
       var size= document.getElementsByTagName("span");
    for(var o in size){
    document.getElementsByTagName("span")[o].style.backgroundColor='red';
    }
       
    });
    </script>
    </head>
    <body>
    <span>全部</span>
    <p>r,我d会434消失。</p>
    <p>点击我,er消d失。</p>
    <span>54545</span>
    <p>也要点击我哦。</p>
    <span>全部dwewe</span></body>
    </html>
      

  4.   

    直接在页面写个单独的样式:
    <style>
       span{color:blue;}
    </style>