如何让<a>标签的href属性先执行,然后再执行onclick事件。

解决方案 »

  1.   

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function ss(a){
    window.setTimeout(function(){alert(a.href)},2000);
    }
    </script>
    </head><body>
    <a href="http://www.baidu.com"  target="_blank" onclick="ss(this)">a</a>
    </body>
    </html>
    让click里的事件延时执行试试
    不过不明白你到底要实现什么样的效果
      

  2.   

    LZ想表达啥意思?
    貌似 相应href属性必须先点击吧,点击之后才会相应href链接, 你现在要先执行href链接再相应onclick事件,好纠结哦
      

  3.   

    我要实现这个效果::<a href="?action=g_&cont=<?php echo $contentid?>&ga=<?php echo $id?>" onclick="this.onclick='';this.removeAttribute('href')" >
    现在得结果是,先执行onclick里的内容,这样 我href里提交的东西就过不去了。
    我的意思是,让它先执行href里的内容,提交后再执行onclick事件。
      

  4.   

    1#已经给出办法了。用计时器延后执行其他操作<a href="?action=g_&cont=<?php echo $contentid?>&ga=<?php echo $id?>" onclick="var me=this;setTimeout(function(){me.onclick='';me.removeAttribute('href')},100);" >
      

  5.   

    你是先执行href提交过去后,然后再删除这个连接吗?
    如果是这样的话,你这个“删除这个链接”可以在你href提交之后执行,不需要放在onclick里,放到href提交过去哪里面去执行,   不知道你懂否,呵呵
      

  6.   

    <a href="http://www.baidu.com"  target="_blank" onclick="ss(this)">a</a>
    可以再ss函数里屏蔽默认执行方法
    如:function ss()
    {
      window.open(url)//模拟链接点击方法
      //onclick事件主要方法
       if ( e && e.preventDefault ) //阻止默认浏览器动作(W3C) 
        e.preventDefault(); 
       else//IE中阻止函数器默认动作的方式 
       {
         window.event.returnValue = false; 
         return false;
       }
    }