[英]How to get alert message on second click of a button
I would like to know that how can I get an alert message on second click of a button, not on a first click. 我想知道如何在第二次单击按钮而不是第一次单击时获得警报消息。
ex: <input type="button" value="Message" onclick="showMessage()">
例如:
<input type="button" value="Message" onclick="showMessage()">
function showMessage(){
alert("It's a second click message"); // this alert message should be shown on second click of a button
}
Use counter instead.. 使用计数器代替。
var count = 0; //global variable function showMessage() { if (count++ == 1) { //Compare and then increment counter alert("It's a second click message"); //this alert message will be shown only on second click of a button } }
<input type="button" value="Message" onclick="showMessage()">
If you are not looking for the dbclick event, then you can use a flag to check whether it is the second click to show the alert 如果您不查找dbclick事件,则可以使用一个标志来检查是否是第二次单击以显示警报
var flag; function showMessage() { if (flag) { alert("It's a second click message"); // this alert message should be shown on second click of a button } else { flag = true; } }
<input type="button" value="Message" onclick="showMessage()">
Consider this code, This is alert message after every alternate click: 考虑以下代码,这是每两次单击后的警报消息:
var count = 1; function showMessage() { if (!(count++ % 2)) alert("It's a second click message"); //this alert message at every second click }
<input type="button" value="Message" onclick="showMessage()" />
use ondblclick
instead of onclick
使用
ondblclick
代替onclick
Like below 像下面
<input type="button" value="Message" ondblclick="showMessage()">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.