Listen to double click not click

前端 未结 6 2046
情歌与酒
情歌与酒 2020-12-15 08:55

I\'m just wondering why click event happening when I dbclick an element?

I have this code:(JSBIN)

HTML

&l         


        
6条回答
  •  情书的邮戳
    2020-12-15 09:24

    This works for me (using the d3 library, but d could also be a dictionary object):

    function log(s){try{console.log(s)}catch(e){}} // for debugging
    
    var click_d = null
    
    function click(d){
        log("click")
        click_d = d
        setTimeout(click_action, 200)
    }
    
    function click_action(){
        log("click_action")
        if(click_d == null){
            log("aborted")
            return
        }
        d = click_d
    
        // do things with d
    }
    
    function doubleclick(d){
        log("dblclick")
        click_d = null
    
        // do things with d
    }
    

提交回复
热议问题