📌  相关文章
📜  通过单击按钮执行更多操作 - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:47.734000             🧑  作者: Mango

代码示例1
let caoButton = document.querySelector('.js-cao-2');

caoButton.addEventListener('click',firstFunctionality);

function firstFunctionality(){
  caoButton.removeEventListener('click', firstFunctionality)
  caoButton.addEventListener('click',secondFunctionality);
  //do stuff here
}

function secondFunctionality(){
  caoButton.removeEventListener('click', secondFunctionality)
  caoButton.addEventListener('click', firstFunctionality);
  //do something different here
}