Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调用两个javascripts函数onClick_Javascript - Fatal编程技术网

调用两个javascripts函数onClick

调用两个javascripts函数onClick,javascript,Javascript,目前我的一个网页上有以下代码- <a href="http://ex.com" onclick="return popitup2()">Grab Coupon</a> 现在有人能告诉我,当点击链接时,如何调用这两个JavaCSript吗。提前感谢。在链接中指定这两个选项: <a href="http://ex.com" onclick="recordOutboundLink(this, 'Outbound Links', 'ex.com'); return pop

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

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

现在有人能告诉我,当点击链接时,如何调用这两个JavaCSript吗。提前感谢。

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

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

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

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

<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>

window.onload=函数(){
var mylink=document.getElementById('mylink');
如果(mylink!=null){
mylink.onclick=函数(){
var res=popitup2();
recordOutboundLink(这是“出站链接”、“ex.com”);
返回res;
};
}
};

您可以通过关闭来完成:

<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>


此语法似乎错误。在
onclick
处理程序中不能有多个
return
语句,或者至少它不是很好。如果函数recordOutboundLink中没有return false,它会以同样的方式工作吗?我很确定您希望返回
popitup2()
,以维护OP的当前函数。
<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>