Disabling onclick attribute with javascript

前端 未结 7 630
梦如初夏
梦如初夏 2021-01-05 14:09

How do I disable the other onclick event once one of them has been activated. Both divs are set to display:none; in the CSS. This is probably really simple but I am new to p

7条回答
  •  北海茫月
    2021-01-05 14:58

    function showDiv(id) {
        if ( showDiv.executed ) {
            return false;
        }
    
        if  ( id === "leftbutton" ) {
           document.getElementById('orangediv').style.display = 'block';
        } else {
           document.getElementById('greendiv').style.display = 'block';
        }
    
        showDiv.executed = true;
    }
    
    showDiv.executed = false;
    

    Doing it this way, you could always re-enable the showing by simply setting showDiv.executed to false.

提交回复
热议问题