Set element to unclickable and then to clickable

前端 未结 6 849
花落未央
花落未央 2021-02-04 04:26

I want to have a div element set to not be clickable and then set it to clickable after another element is clicked.

So, when .case is clicked:

$(\'.case\         


        
6条回答
  •  长发绾君心
    2021-02-04 05:21

    Depending on your need (Only one element or many, dynamic element creation or not) you can use :

    1) A variable to check if the first click on the other element has been done

    var isActive  = false;
    
    $('.case').click(function() {  
        isActive = true;
    });
    
    $('#patient').click(function(){
        if(isActive === false)
            return false;
    
        //Your behaviour
    });
    

    2) Define the click function in the click event of the first element

    $('.case').on('click',function() { 
        //Make element clickable 
        $('#patient').on('click',function(){
            //Your behaviour
        });
    });
    

    Then you can use off to remove the click event

提交回复
热议问题