下面頂部函數中的一個case語句不按順序執行。目前,它直接提示,如果您點擊取消,operatorPickup
從來沒有聽說過。如果我輸入「警察」,我得到了警方的記錄是在稱爲在當前功能的末和然後我得到OperatorAnswer
不同的功能,這使得完全沒有意義的,它是在2階去,3,1 - 當3甚至不在相同的功能!JavaScript函數拒絕按順序執行
根據以前的經驗,我嘗試了延遲提示,以防提醒,提示或確認阻止用戶界面並優先考慮,但這也沒有幫助。
function response() {
switch(number) {
case "0":
var operatorPickup = new Audio('OperatorAnswer.wav');
operatorPickup.play();
setTimeout(function() {
number = prompt("Operator, your number please? (Numbers only; enter 'police' for police and emergency)");
number = number;
operatorPutCallThrough();
}, 9);
break;
case "911":
var pickup911 = new Audio('911-xxx-fleet.mp3');
pickup911.play();
break;
case "18477651008":
var pickupMCI = new Audio('MCI.wav');
pickupMCI.play();
break;
case "8675309":
var pickup8675309 = new Audio('discoornis-bell-f1.mp3');
pickup8675309.play();
break;
case "police":
break;
default:
var pickupDefault = new Audio('ldcircuits-bell-f1.mp3');
pickupDefault.play();
}
}
function operatorPutCallThrough() {
if (number == "police") {
var operatorPoliceTransfer = new Audio('OperatorPolice.wav');
operatorPoliceTransfer.play();
}
response();
}
我怎麼能強迫的情況下 「0」 switch(number)
爲了執行?
如果我這樣做,根本不會播放任何錄音,但警告框不會彈出。一切只是停止 – InterLinked
這是沒有意義的...你有控制檯中的任何錯誤?你是否在'var operatorPickup = new Audio('OperatorAnswer.wav');''和operatorPickup.play();'之間添加了eventlistener? –
我在var operatorPickup定義之前就已經完成了,解決了它! – InterLinked