0
每次用戶啓動應用程序時,應用程序會要求用戶選擇「第一個」或「第二個」。 如果用戶的選擇是「第一」,則顯示消息「測試1」,或者如果用戶的選擇是「第二」,則消息是「測試2」。消息對話框用戶選擇Metro應用程序 - JavaScript
不管我選擇的消息總是「測試1」。
我的代碼有什麼問題?
我怎樣才能使它工作?
var msg = new Windows.UI.Popups.MessageDialog("Choose first or second.", "Test");
// Add commands and set their command handlers
msg.commands.append(new Windows.UI.Popups.UICommand("First", commandInvokedHandler));
msg.commands.append(new Windows.UI.Popups.UICommand("Second", commandInvokedHandler));
// Set the command that will be invoked by default
msg.defaultCommandIndex = 1;
// Set the command to be invoked when escape is pressed
msg.cancelCommandIndex = 1;
// Show the message dialog
msg.showAsync();
if (msg = 1) {
// First Choice
var button = document.getElementById("button");
applyButton.addEventListener("click", buttonFirst, false);
} else {
// Second Choice
var button = document.getElementById("button");
applyButton.addEventListener("click", buttonSecond, false);
}
function buttonFirst(eventInfo) {
var greetingString = "TEST 1";
document.getElementById("first").innerText = greetingString;
}
function buttonSecond(eventInfo) {
var greetingString = "TEST 2";
document.getElementById("second").innerText = greetingString;
}
它仍然無法正常工作。 – kalpetros
請參閱我的編輯。不知道這是否會解決它,但我有一種感覺可能有所幫助 – n00dle
我試過了,它不起作用。我所做的是我用'buttonFirst'和'buttonSecond'替換了'commandInvokedHandler',並且我還從事件處理程序中刪除了'if else'。我不確定我是否做得對。 – kalpetros