Help regarding Click and Double click events
I am having this strange problem and finding it difficult to sort it out..
I am using 2 AJAX requests based on click and double click events. When i single click the bottom pane is updated with new content (like yahoo mail), and when i double click, i am开发者_JAVA技巧 opening a dialog window. Is there any way that i can check whether the user has double clicked first, else use the single click event ??..
Currently the way that i am doing, i am getting 3 AJAX requests for double click, one for the Dbclick and the other two for the click events.. pls share some light on how to proceed with this... the script is as follows..
$('.dataLink').live("click", function() {
$('#contentBottom').load('bottompane.html');
});
$(".dataLink").live("dblclick", function() {
$('.plotter').load('Modalwindow.html').dialog('open');
});
Form Jquery Api
It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events and others only one. If an interface that reacts differently to single- and double-clicks cannot be avoided, then the dblclick event should be simulated within the click handler. We can achieve this by saving a timestamp in the handler, and then comparing the current time to the saved timestamp on subsequent clicks. If the difference is small enough, we can treat the click as a double-click.
Use "state" variables say, ajaxLoadingSingle and ajaxLoadingDouble, to keep track of when the events are occurring. At the beginning of each call to ajax check for state and return false if it's already loading and/or should be handled by the other handler, otherwise turn on the appropriate variable. Turn the state variables off in your load form method.
精彩评论