繁体   English   中英

Minesweeper在JavaScript中删除事件监听器

[英]Minesweeper Remove event listener in javascript

我为扫雷游戏创建了两个事件监听功能。 当我输掉游戏时,我想删除事件侦听器,以便输掉之后无法单击单元格。 我该怎么做?

谢谢

board.oncontextmenu = function(e) {
    var  cellIndex = e.target.cellIndex;
    var rowIndexx = e.target.parentNode.rowIndex;            
    right_click(rowIndexx, cellIndex);
}

board.onclick = function(e) {
    var rowIndex = e.target.cellIndex;
    var cellIndex = e.target.parentNode.rowIndex;
    console.log("coluna: " + cellIndex + " linha: " + rowIndex);

    if (primeira_jogada == 0 ) { timer(); }

    if (isBomb(cellIndex, rowIndex) && firstmove == 0) {
        moveBomb(cellIndex, rowIndex);
        refresh();
    }

    if (isBomb && primeira_jogada !== 0) {
        lose();
        //event lister stops here
    }
}

使用addEventListener和removeEventListener( https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM