0

ユーザーがアプリを起動するたびに、アプリはユーザーに "First" または "Second" を選択するよう求めます。ユーザーの選択が「First」の場合、メッセージ「TEST 1」が表示されます。ユーザーの選択が「Second」の場合、メッセージは「TEST 2」です。

何を選択しても、メッセージは常に「TEST 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;
}
4

1 に答える 1

0

if(msg = 1) {それ以外の場合if(msg == 1) {は、1 に設定してからチェックします。

編集:

よく調べてみると、ここにはもっと大きな問題があります。eventListeners を個別に追加する理由 UICommand クラスの仕様には、2 番目のパラメーターがコールバックであると記載されています。したがって、ボタンを作成する方法の代わりに、次のようにしてください。

msg.commands.append(new Windows.UI.Popups.UICommand("First", buttonFirst));

msg.commands.append(new Windows.UI.Popups.UICommand("Second", buttonSecond));
于 2013-06-05T22:20:13.633 に答える