消息对话框用户选择Metro应用程序-JavaScript
每次用户启动应用程序时,应用程序都会要求用户选择第一个或第二个。 如果用户的选择是第一个,则显示消息TEST 1;如果用户的选择是第二个,则显示消息TEST 2 无论我选择什么,消息总是测试1 我的代码有什么问题 我怎样才能让它工作消息对话框用户选择Metro应用程序-JavaScript,javascript,Javascript,每次用户启动应用程序时,应用程序都会要求用户选择第一个或第二个。 如果用户的选择是第一个,则显示消息TEST 1;如果用户的选择是第二个,则显示消息TEST 2 无论我选择什么,消息总是测试1 我的代码有什么问题 我怎样才能让它工作 var msg = new Windows.UI.Popups.MessageDialog("Choose first or second.", "Test"); // Add commands and set their command handlers msg
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;
}
ifmsg=1{应该是ifmsg==1{否则将其设置为1,然后进行检查
编辑:
仔细检查,这里有更大的问题。为什么要单独添加eventListeners?说明第二个参数是回调。因此,与其使用创建按钮的方式,不如:
msg.commands.append(new Windows.UI.Popups.UICommand("First", buttonFirst));
msg.commands.append(new Windows.UI.Popups.UICommand("Second", buttonSecond));
请查看我的编辑。不确定这是否会修复它,但我感觉它可能会有所帮助。我尝试了它,但它不起作用。我所做的是将commandInvokedHandler替换为buttonFirst和buttonSecond,并从事件处理程序中删除了if-else。我不确定我是否做得对。我假设您确实有ID为第一个和第二个的两个元素?Ye他们的身份证是第一和第二。在这种情况下,我没有主意了。对不起