Javascript Clicker客户队列按钮调用密码



我有下面的代码(Javascript和HTML(:

function uppass(e) {
var element = document.getElementById("newclient");
let value = element.innerHTML.replace(/[^0-9]/g, "");
++value;
let newValue=e.id +'  -  ' +value ;
document.getElementById("newclient").innerHTML =  newValue;
}
<!DOCTYPE HTML>
<html>
<head>
<title>
clicked button in JavaScript
</title>
</head>
<body style="text-align:center;">
<header>
<h1> Clicker customer queue window calling</h1>
</header>
<h4><b>For customers</b></h4>
<center>
<button id="c" class="button" onclick="uppass(this)" style=" font-size: 16px; margin: 0 10px;"> Common </button>
<button id="f" type="button" onclick="uppass(this)" style=" font-size: 16px; margin: 0 10px;"> Fast </button>
<button id="p" type="button" onclick="uppass(this)" style=" font-size: 16px; margin: 0 10px;"> Priority </button>
</center>
<h5>Your pass is: </h5>
<h2 id="newclient" style="font-size: 12px; display: inline-block; padding-left: 20px;">0</h5>
<br><br>
<h4><b>Attendant Call</b></h4>
<button id="window1" type="button" onclick="funcao()" style=" font-size: 16px; margin: 0 10px;"> Window 1 </button>
<button id="window2" type="button" onclick="funcao()" style=" font-size: 16px; margin: 0 10px;"> Window 2 </button>
<button id="window3" type="button" onclick="funcao()" style=" font-size: 16px; margin: 0 10px;"> Window 3 </button>
<button id="window4" type="button" onclick="funcao()" style=" font-size: 16px; margin: 0 10px;"> Window 4 </button>
</center>
<br><br>
<h5>Calling password number:</h5><h2 id="newclient" style="font-size: 12px; display: inline-block; padding-left: 20px;">0</h5>
</body>
</html>

我正在努力使";窗口";调用在";Common""快";以及";优先级";按钮
例如。如果客户端在";Common""优先级";或";快速";,";窗口";将调用该密码
但我在javascript中创建它时遇到了问题,可能是用数组和"如果";方法,但也可能是另一种方法
最难的部分是:
"窗口1";调用密码";"优先级",如果没有,则调用密码";"快";,如果没有,则调用密码";普通的";如果没有,它就什么都不做。"窗口2";以及";窗口3";调用密码";"快",如果没有,则调用密码";"优先级";,如果没有,则调用密码";普通的";如果没有,就什么也不做。"窗口4";调用密码";Common",如果没有,则调用密码";"优先级";,如果没有,则调用密码";"快";如果没有,它就什么都不做。

每个";窗口";有按钮。当点击按钮时,它验证要调用的下一个密码,在面板上显示密码,显示";窗口";并将其从队列中删除。如果队列中没有密码,则不会执行任何操作。

有人能帮忙吗?感谢

上的代码https://jsfiddle.net/ofr8kv05/

为每个队列创建阵列:

  • Common=cq[]
  • Fast=fq[]
  • 优先级=pq[]

每次按下客户密码时,密码都会添加到相应的队列中并显示。

每次按下窗口时,都会根据规则构建orderedQueue,显示第一个密码,并将其从orderedQueue和匹配的单个队列/阵列(cq[]fq[]pg[](中删除。

let cq = [] // Common Queue
let fq = [] // Fast Queue
let pq = [] // Priority Queue
function uppass(e) {
var newClient = document.getElementById("newclient")
let value = newClient.innerHTML.replace(/[^0-9]/g, "")
++value

// Add to appropriate queue
switch (e.id) {
case "c": // Common Queue
cq.push(value)
break
case "f": // Fast Queue
fq.push(value)
break
case "p": // Priority Queue
pq.push(value)
break
}

newClient.innerHTML = e.id + ' - ' + value
//console.log("cq: [" + cq + "]")
//console.log("fq: [" + fq + "]")
//console.log("pq: [" + pq + "]")
}
function funcao(e) {
let orderedQueue = []
let callClient = document.getElementById("callclient")
// Build orderedQueue
switch (e.id) {
case "window1":
orderedQueue = pq.concat(fq.concat(cq))
break
case "window2": case "window3":
orderedQueue = fq.concat(pq.concat(cq))
break
case "window4":
orderedQueue = cq.concat(pq.concat(fq))
break
}
if (orderedQueue.length == 0) {
callClient.innerHTML = "No customers."
} else {
firstInQueue = orderedQueue.shift()
// Remove firstInQueue from queue
if (firstInQueue == cq[0]) {
cq.shift()
fromQueue = "c"
} else if (firstInQueue == fq[0]) {
fq.shift()
fromQueue = "f"
} else if (firstInQueue == pq[0]) {
pq.shift()
fromQueue = "p"
}
callClient.innerHTML = fromQueue + " - " + firstInQueue
//console.log("orderedQueue: [" + orderedQueue + "]")
//console.log("cq: [" + cq + "]")
//console.log("fq: [" + fq + "]")
//console.log("pq: [" + pq + "]")
}
}
<!DOCTYPE HTML>
<html>
<head>
<title>
clicked button in JavaScript
</title>
</head>
<body style="text-align:center;">
<header>
<h1>Clicker customer queue window calling</h1>
</header>
<h4><b>For customers</b></h4>
<button id="c" class="button" onclick="uppass(this)" style=" font-size: 16px; margin: 0 10px;">Common</button>
<button id="f" type="button" onclick="uppass(this)" style=" font-size: 16px; margin: 0 10px;">Fast</button>
<button id="p" type="button" onclick="uppass(this)" style=" font-size: 16px; margin: 0 10px;">Priority</button>
<h5>Your pass is:</h5>
<h2 id="newclient" style="font-size: 12px; display: inline-block; padding-left: 20px;">0</h2>
<br><br>
<h4><b>Attendant Call</b></h4>
<button id="window1" type="button" onclick="funcao(this)" style=" font-size: 16px; margin: 0 10px;">Window 1</button>
<button id="window2" type="button" onclick="funcao(this)" style=" font-size: 16px; margin: 0 10px;">Window 2</button>
<button id="window3" type="button" onclick="funcao(this)" style=" font-size: 16px; margin: 0 10px;">Window 3</button>
<button id="window4" type="button" onclick="funcao(this)" style=" font-size: 16px; margin: 0 10px;">Window 4</button>
<br><br>
<h5>Calling password number:</h5>
<h2 id="callclient" style="font-size: 12px; display: inline-block; padding-left: 20px;">0</h2>
</body>
</html>

相关内容

最新更新