admin管理员组文章数量:1401199
I have function to detect idle state of user. I want to update database if any of the event occurs.Now i have script like this
$("body").mousemove(function(event) {
myfuction();
});
I want to convert above script like this
$("body").anyOfTheEvent(function(event) {
myfuction();
});
How can i do this?
I have function to detect idle state of user. I want to update database if any of the event occurs.Now i have script like this
$("body").mousemove(function(event) {
myfuction();
});
I want to convert above script like this
$("body").anyOfTheEvent(function(event) {
myfuction();
});
How can i do this?
Share Improve this question asked Aug 8, 2012 at 9:41 EbinPauloseEbinPaulose 1,1393 gold badges14 silver badges26 bronze badges 3- 3 Why do you need to detect user's idle state? It may be you're having a design flaw in your application because this may put your web application to crawl. Expecially if you'll wire Ajax requests to your events (mentioning DB). It will surely make it pletely unusable. Believe me. All event's transferred to DB will surely halt it. A simple mouse move happens much more frequently than you can wire these events to the server and store them in the database. – Robert Koritnik Commented Aug 8, 2012 at 9:44
- I have a time limit in "Myfuction".only one Ajax request occur per 2 minute – EbinPaulose Commented Aug 8, 2012 at 9:49
- Still: Why do you need to detect user idle state? – Robert Koritnik Commented Aug 8, 2012 at 9:52
5 Answers
Reset to default 2You can find the event name using the e.type property. Try looking this example
$('#element').bind('click dblclick mousedown mouseenter mouseleave',
function(e){
alert("EventName:"+e.type);
});
The jsfiddle for this is here http://jsfiddle/qp2PP/
You could have an array of the events you're interested in and subscribe to all of them
var events = ['click','mousemove','keydown'] // etc
$.each(events,function(i,e){
$('body')[e](myfuction);
});
Get a list of events here: http://api.jquery./category/events/
You can bind more than one event with bind()
$('#foo').bind('click mousemove', function(evt) {
console.log(evt.type);
});
just use on()
, with a space-delimited list of events:
$('body').on('mousedown click', function(e) {
var eventType = e.type;
// do stuff
});
References:
on()
.
Instead of bind to specific element, you can bind directly to document.
$(document).bind('click mousemove', function(evt) {
document.getElementById("demo").innerHTML = Math.random();
});
Example in CODEPEN
本文标签: javascriptHow detect any of all events using jqueryStack Overflow
版权声明:本文标题:javascript - How detect any of all events using jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744197783a2594822.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论