页面有多个div 切每个div套有超链接 如:
<div class="a"><a href="a.html"></a></div>
<div class="a"><a href="b.html"></a></div>
<div class="a"><a href="c.html"></a></div>
<div class="a"><a href="d.html"></a></div>
如何让页面加载时默认执行第一个DIV的超链接事件 默认页面加载后就跳到a.html
JS和JQUERY都可以 急急急~

解决方案 »

  1.   

    $(document).ready(function () {
            $(".a").click();
        });自己用JQUERY这样写 但没有跳转
      

  2.   

    而且默认还是最后一个DIV被点击了 不是第一个DIV
      

  3.   


    $(document).ready(function () {
        location.href = $(".a").attr("href");
    });
      

  4.   

    window.location.href = "a.htm";
      

  5.   

    $(document).ready(function () {
        location.href = $(".a")[0].href;
    });
      

  6.   

    这个是正确的,被楼上绕进去了$(document).ready(function () {
        location.href = $(".a:eq(0) a")[0].href;
    });
      

  7.   


    你不就是要问怎么跳转么?
    哦,是不是因为我没写
    本例中,文本 "Page is loaded" 会被显示在状态栏中:<html>
    <head>
    <script type="text/javascript">
    function load()
    {
    window.location.href = "a.htm";
    }
    </script>
    </head><body onload="load()">
    </body></html>
      

  8.   

    8L +1class a中选取第一个 也可以这样试试$(document).ready(function () {
          window.location.href=$(".a:eq(0) a").attr("href");
    });
      

  9.   

    很简单啊
    $('div.a').first().find('a').trigger('click');
      

  10.   

    $(document).ready(function(){location.href=$("div:first a").attr("href")});
      

  11.   

    曾见过有人提过这个问题... ... 我给了他这个方法... ...却... ... 不结贴....function e(event){
        var evt = event || window.event;
        var target = evt.target || evt.srcElement;
        window.location = target.id+".html";
    }
    /*
       @linkId : 不需要跳转的 A 元素 ID
    */
    function setLinks(linkId){
        var menus = document.getElementById("menus").getElementsByTagName("a");
        for(var i=0; i< menus.length; i++){
            if(menus[i].id.toLowerCase() != linkId.toLowerCase()){
                 if (window.attachEvent){
                     menus[i].attachEvent('click',e)
                 }else if(window.addEventListener){
                     menus[i].addEventListener('click',e,false)
                }
            }   
        }
         
    }
    window.onload = function(){
        setLinks('a1');
    }
    <div id="menus">
        <a ID=a1 href="#"> 菜单1</a>
        <a ID=a2 href="#"> 菜单2</a>
        <a ID=a3 href="#"> 菜单3</a>
        <a ID=a4 href="#"> 菜单4</a>
    </div>
      

  12.   

    最后解决了
    给 a 标签加上 ID或class  然后 
    location.href = $("#id名").attr("href");或
    location.href = $(".class名").attr("href");调用点击事件只能是a标签的链接 调用外围的DIV不起作用的
    谢谢大家 分都给大家