如何钩到页面宽点击事件? [英] How to hook into the page wide click event?

查看:119
本文介绍了如何钩到页面宽点击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像问题状态。我想在每次用户点击网页时触发一个调用方法的事件。



如何在不使用jQuery的情况下这样做?

$没有使用jQuery,我想你可以这样做:

 >  if(document.addEventListener){
document.addEventListener('click',
function(event){
// handle event here
}
false
);
} else if(document.attachEvent){
document.attachEvent('onclick',
function(event){
// handle event here
}
);
}


Just like the question states. I want to fire off an event that calls a method everytime the user clicks on the web page.

How do I do that without use of jQuery?

解决方案

Without using jQuery, I think you could do it like this:

if (document.addEventListener) {
    document.addEventListener('click',
        function (event) {
            // handle event here
        },
        false
    );
} else if (document.attachEvent) {
    document.attachEvent('onclick',
        function (event) {
            // handle event here
        }
    );
}

这篇关于如何钩到页面宽点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆