即時通訊嘗試做一個循環,執行代碼並觀察手機alpha,然後轉到特定頁面,但我的循環只能處理我的第一個和第二個case if和frist else if。 .. 即時有點失去,我不知道還有什麼其他的事情...會喜歡一些幫助thx很多!JavaScript循環槽多個條件
window.addEventListener("deviceorientation",findPlace);
for (var i = 0; i < count; i++) {
findPlace();
}
function findPlace(evt) {
if (evt.alpha < 90 || evt.alpha > 360) {
unit.goToScreenAction(ctx, { screen: unit.find('Norte') }, noop);
window.alpha = evt.alpha;
unit.find('alphatxt').setText(window.alpha + '');
}
else if (evt.alpha < 180 || evt.alpha > 90) {
unit.goToScreenAction(ctx, { screen: unit.find('Este') }, noop);
window.alpha = evt.alpha;
unit.find('alphatxt3').setText(window.alpha + '');
}
else if (evt.alpha < 360 || evt.alpha > 270) {
unit.goToScreenAction(ctx, { screen: unit.find('Sur') }, noop);
window.alpha = evt.alpha;
unit.find('alphatxt1').setText(window.alpha + '');
}
else if (evt.alpha < 270 || evt.alpha > 180) {
unit.goToScreenAction(ctx, { screen: unit.find('Oeste') }, noop);
window.alpha = evt.alpha;
unit.find('alphatxt2').setText(window.alpha + '');
}
else {
unit.goToScreenAction(ctx, { screen: unit.find('Nada') }, noop);
}
}
你能澄清一下你想要每個特定的if/else-if語句來測試嗎?我有一種感覺,你的一些'||'應該是'&&'。 –
'findPlace()'需要一個'evt'參數,但是你沒有在循環中傳遞任何參數。 – Barmar
@ J.Chen我很確定*他們中的所有*應該是'&&'。 – Barmar