试图弹出双重确认。如果我点击按钮,弹出窗口就会打开。在这里,如果我点击“是”按钮,它应该转到按钮页面(第一页)。如果我点击没有其他窗口应该打开OK按钮。如果我点击确定按钮,则应关闭所有弹出窗口。
function confirmation(question) {
var defer = $.Deferred();
$('<div></div>')
.html(question)
.dialog({
autoOpen: true,
buttons: {
"Yes": function() {
defer.resolve("true");
},
"No": function() {
defer.resolve("false");
}
},
});
return defer.promise();
};
function onclick() {
var question = "Do you want to add record?";
confirmation(question).then(function(answer) {
console.log(answer);
var ansbool = (String(answer) == "true");
if (ansbool) {
// alert("this is obviously " + ansbool);//TRUE
} else {
// alert("and then there is " + ansbool);//FALSE
}
});
}
$("#item").on('click', onclick);
#item:hover {
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="item">click me.</button>