页面元素的ID是唯一的,你可以设置不同的ID,然后根据ID获取到修改的a,然后更改如果批量的话,获取元素可以利用getElementsByTagName('a'),然后循环设置

解决方案 »

  1.   

    一个页面只能存在唯一的一个不同的id值 想取到多个建议用class去定义
      

  2.   

    document.getElementsByTagName("a").href="http:www.baidu.com"
      

  3.   

     window.onload=function(){    
    var aa=document.getElementsByTagName("a");
    for(var i=0;i<aa.length;i++){
    aa[i].href="http:www.baidu.com"; 
    }
    }
      

  4.   


    window.onload=function(){
        var aList=document.getElementsByTagName("a");
        for(var i=0,len=aList.length;i<len;i++){
            aList[i].href="http://www.baidu.com";
        }
    };
      

  5.   

    你id一样都冲突了, 肯定是不行的啦,你可以使用class来批量修改,借用楼上代码修改之<script type="text/javascript">
            window.onload=function(){    
    var aList=document.getElementsByTagName("a");
         for(var i=0,len=aList.length;i<len;i++){
    if(aList[i].className=="promotion"){
    aList[i].href="http://www.baidu.com";
    }
         }
    }
    </script>
    </head><body>
    <div class="js_1">
        <a href="http://www.hao123.com" class="promotion">aaaa</a>
        <a href="http://www.hao123.com" class="promotion">aaaab</a>
        <a href="http://www.hao123.com" class="noPromotion">class不为promotion则链接不改变</a>
    </div>
    </body>
    </html>
      

  6.   

    楼上的调试下<a href="http://www.hao123.com" class="noPromotion">class不为promotion则链接不改变</a>
    </div>出先乱码