代码之家  ›  专栏  ›  技术社区  ›  ayush

调用两个javascripts函数onClick

  •  5
  • ayush  · 技术社区  · 14 年前

    目前我的一个网页上有以下代码-

    <a href="http://ex.com" onclick="return popitup2()">Grab Coupon</a>
    

    现在我想再运行一个脚本,它的用法如下-

    onClick="recordOutboundLink(this, 'Outbound Links', 'ex.com');return false;"
    

    3 回复  |  直到 14 年前
        1
  •  9
  •   Darin Dimitrov    14 年前

    可以在onclick事件处理程序中调用以下两个函数:

    <a href="http://ex.com" onclick="popitup2(); recordOutboundLink(this, 'Outbound Links', 'ex.com'); return false;">Grab Coupon</a>
    

    onclick 此特定链接的事件如下:

    <a href="http://ex.com" id="mylink">Grab Coupon</a>
    

    而在 head 章节:

    <script type="text/javascript">
    window.onload = function() {
        var mylink = document.getElementById('mylink');
        if (mylink != null) {
            mylink.onclick = function() {
                var res = popitup2(); 
                recordOutboundLink(this, 'Outbound Links', 'ex.com');
                return res;
            };
        }
    };
    </script>
    
        2
  •  2
  •   Sarfraz    14 年前

    在链接中指定这两个选项:

    <a href="http://ex.com" onclick="recordOutboundLink(this, 'Outbound Links', 'ex.com'); return popitup2();">Grab Coupon</a>
    
        3
  •  1
  •   Mark Elliot    14 年前

    <a href="http://ex.com" onclick="return function(){ recordOutboundLink(this, 'Outbound Links', 'ex.com'); return popitup2(); }()">Grab Coupon</a>
    

    或者只是一些更好的命令:

    <a href="http://ex.com" onclick="recordOutboundLink(this, 'Outbound Links', 'ex.com');return popitup2();">Grab Coupon</a>