I'm in the middle of a project where I need to show a popup when two or more buttons have been clicked.(我在一个项目的中间,当单击两个或更多按钮时,需要显示一个弹出窗口。)
Does anyone know how to do that?(有谁知道这是怎么做到的吗?) ask by Ana Fernández translate from soI'm in the middle of a project where I need to show a popup when two or more buttons have been clicked.(我在一个项目的中间,当单击两个或更多按钮时,需要显示一个弹出窗口。)
Does anyone know how to do that?(有谁知道这是怎么做到的吗?) ask by Ana Fernández translate from soTry the javascript below.(试试下面的javascript。)
var clicks = 0; var buttons = document.getElementsByTagName("button"); for (i = 0; i < buttons.length; i++){ buttons[i].addEventListener("click", function(){ clicks++; if(clicks >= 2){ alert('Pop-up. ' + clicks + ' clicks have been recorded.'); } }); }
<button>Button 1</button> <button>Button 2</button> <button>Button 3</button>