0

每次用户启动应用程序时,应用程序都会要求用户选择“第一”或“第二”。如果用户的选择是“第一”,则显示消息“TEST 1”,或者如果用户的选择是“第二”,则消息是“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 类的规范声明第二个参数是回调。因此,不要使用创建按钮的方式,为什么不这样做:

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 回答