javascript - 如何制作 JS 多按钮?
问题描述
我有名为 1,2 和 3 的按钮。下面是 a、b、c、d 按钮。当我单击第一个按钮并单击“A”按钮时,我收到 (Test Test2) 警告。但我无法单击第二个按钮并单击“A”按钮。我想再发出一个警告。例如:我单击第一个按钮,然后单击 A 按钮,如屏幕上显示的 (Test Test6),但我不能。谢谢。
var firstButtonPressed = false;
function onFirstButtonClick() {
firstButtonPressed = true;
}
function onfourButtonClick() {
if(firstButtonPressed) {
alert('Test Test2');
firstButtonPressed = false;
} else {
alert('Test2');
}
return;
}
var secondButtonPressed = false;
function onSecondButtonClick(){
secondButtonPressed = true;
}
function onFourButtonClick(){
if(secondButtonPressed){
alert('Button2 Test');
secondButtonPressed = false;
}else {
alert ('61 Tes-t')
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<button type="button" onclick="onFirstButtonClick()">1<br><br>Button</button>
<button type="button" onclick="onSecondButtonClick()">2<br><br>Button</button>
<button type="button" onclick="onThirdButtonClick()">3<br><br>Button</button>
<br /><br>
<button type="button" onclick="onfourButtonClick()">A</button>
<button type="button" onclick="onfiveButtonClick()">B</button>
<button type="button" onclick="onsixButtonClick()">C</button>
<button type="button" onclick="onsevenButtonClick()">D</button>
</body>
</html>
解决方案
推荐阅读
- office365 - 可以将两个 Outlook Web 插件放在一组中
- java - 带有 Angular 5 的 Spring Boot Websocket 安全性
- windows - 如何使用 powershell 禁用防病毒和启用 Windows Defender
- python - 如何使用 Scikit-Learn 在 Python 中实现斐波那契数列?
- marklogic - MarkLogic REST PUT 添加文档返回 500 内部服务器错误
- c++ - 缺少 PIMAGE_DOS_HEADER 上的 MSDN 文档?
- wordpress - WooCommerce 结帐“错误处理结帐。请重试。”
- r - R中的数值错误
- ios - 快速语音识别
- docker - Linux 托管和 .NET Core Docker:PlatformNotSupportedException:此平台不支持 System.DirectoryServices.AccountManagement