在onClick上调用两个javascripts函数 [英] Calling two javascripts functions onClick
本文介绍了在onClick上调用两个javascripts函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我的网页上有以下代码 -
Presently i have the following code on one of my web page-
<a href="http://ex.com" onclick="return popitup2()">Grab Coupon</a>
现在我想再运行一个以下列方式使用的脚本 -
now I want to run one more script which is used in the following way -
onClick="recordOutboundLink(this, 'Outbound Links', 'ex.com');return false;"
现在有人可以告诉我如何在点击链接时调用这两个javacsripts。在此先感谢。
Now can someone tell me how do i call both of these javacsripts when the link is clicked. Thanks in advance.
推荐答案
您可以在onclick事件处理程序中调用这两个函数:
You can call the two functions in the onclick event handler:
<a href="http://ex.com" onclick="popitup2(); recordOutboundLink(this, 'Outbound Links', 'ex.com'); return false;">Grab Coupon</a>
为避免将标记与javascript混合,我建议你附上 onclick
此特定链接的事件如下:
To avoid mixing markup with javascript I would recommend you attaching the onclick
event for this particular link like this:
<a href="http://ex.com" id="mylink">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>
这篇关于在onClick上调用两个javascripts函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文