How do i assign events to a single element based on click or dblclick. Ive found jsfiddles but none of them are exact. Basically, an imitation of the instagram double tap to like or tap to visit is desired. I know how to bind the events, but not the logic.

有帮助吗?

解决方案

I'm pretty sure you can do what you're asking by using .on() to bind "click" or "dblclick" to a specific element.

Check out this example: http://jsfiddle.net/pcostanz/nSkVU/

Essentially I'm binding some background color changes using .on() to the "click" and "dblclick" events.

$(document).ready(function() {

    $("#singleclick").on("click", function() { 
        $(this).css('background-color', 'orange');
    });

    $("#doubleclick").on("dblclick", function() { 
        $(this).css('background-color', 'orange');
    });    

});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top