<a href="..." onclick="...">...</a>
onclick是在href之前执行的,有什么办法可以让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 change(){
    window.open("http://www.baidu.com");
    alert("a");
    }
    </script>
    </head><body>
    <a href="javascript:change()">aa</a>
    </body>
    </html>
    完全不明白你的意思
      

  2.   

    <a href="javascript:void(0);" name="party_pop"  onclick="party_pop($val[partyid]);location.href='{url party/index/id/$val[partyid]}';">$val[subject]</a>
      

  3.   

    <a href="javascript:void(0);" name="party_pop"  onclick="party_pop($val[partyid]);location.href='{url party/index/id/$val[partyid]}';">$val[subject]</a> 楼上这样的话,onclick还是先执行了party_pop这个函数,然后再跳转啊;我要的是先执行href,然后再执行party_pop函数,怎么做
      

  4.   

    1.<a>打开新页面
    你原来的onclick的方法定义function oldClick(){};
    <a onclick="openWin();">跳转后执行</a>
    function openWin() {var win=window.open(//...url); oldClick();};
    2.<a>覆盖当前页面
    则oldClick需要定义在新页面,需要的参数通过querystring传递过去
      

  5.   

    <a href="xxxxx.html" onclick="window.open(this.href);其他js代码">...</a>
      

  6.   

    如果重新载入新页面后,原来页面的document“消失”,你在原页面定义的函数都是不可用的,新页面无法直接访问原页面的元素,但是打开新页面方式可以实现新老页面的交互,原页面通过新页面句柄win和新页面window.opener得到原页面句柄。
      

  7.   

    更正,取消href的执行<a href="xxxxx.html" onclick="window.open(this.href);其他js代码;return false;">...</a> 
      

  8.   

    <a href="xxxxx.html" onclick="setTimeout(function(){alert('hi');},2000);">...</a>
      

  9.   

    这是在玩你猜你猜你猜猜猜吗?
    href="xxxx" 这个xxx是什么,一段javascript,还是一个url地址如果是url,你没有target='_blank',就如你想可以先href再onclick,但当前页面都不存在了,还onclick撒需求明确一点,例子可以简单,但不要模棱两可。如果你自己举不出合适的例子,那就多说两句,但最原始的需求说明一下
      

  10.   

    没有办法把 onclick 和 href 顺序颠倒关键是,你的 href 里是什么,你想在 href 之后做什么,没说清楚啊,上面那些回答都可以一定程度解决问题
      

  11.   


    例子不完整,只是提供个想法,利用setTimeout方法。作为楼主解决问题的参考而已