我正在尝试根据javascript确认对话框的结果创建一个条件函数。 无论点击什么,似乎都会返回真实状态。有谁看到我做错了什么?
$(function () {
$("#Language").change(function () {
var a = $(this).val();
if (a == 3) {
confirm("Selecting a bilingual calendar will effect the billing. ")
if (confirm) { console.log("test"); }
}
});
});
答案 0 :(得分:4)
if(confirm)
真的没有为你做任何事情(因为它不存在)。试试这个:
// Save the response in a var called userResponse
var userResponse = confirm("Selecting a bilingual calendar will effect the billing. ")
if (userResponse) { console.log("test"); }
您也可以通过简单地在if语句中添加确认来缩短代码:
// confirm() returns true or false. So, when evaluated your if simply says
// if(true) or if(false), depending on the answer.
if (confirm("Selecting a bilingual calendar will effect the billing. ")) {
console.log("test");
}
答案 1 :(得分:2)
$(function () {
$("#Language").change(function () {
var a = $(this).val();
if (a == "3") { // notice the quotation marks
// notice this variable
var confirmed = confirm("Selecting a ... billing.");
if (confirmed) { console.log("test"); }
}
});
});