我必须创建一个jquery的确认模式框,作为默认确认框,返回true或false并在整个项目中工作。
我这样称呼它......
var result = confirm("Are you sure you want exit");
if(result == false)
return false;
else{
//somethings are done here
}
并在Main.js中编写了它的实现如下..
function confirm(message){
$("#alert_cust_message").html(message);
var returnValue = false;
$("#myAlert").dialog({
modal: true,
minHeight: 100,
buttons: {
"OK": function()
{
$( this ).dialog( "close" );
returnValue = true;
},
Cancel: function()
{
$( this ).dialog( "close" );
returnValue = false;
}
}
});
$("#myAlert").parent().css('font-size','9pt');
return returnValue;
}
现在我面临的问题是回归价值......
我没有得到预期的回报,我认为这是由于异步对话。
现在可以轻松解决这个问题吗?
任何帮助将不胜感激..谢谢
答案 0 :(得分:0)
您需要使用回调
function confirm(message, callback) {
$("#alert_cust_message").html(message);
var returnValue = false;
$("#myAlert").dialog({
modal: true,
minHeight: 100,
buttons: {
"OK": function () {
$(this).dialog("close");
callback(true);
},
Cancel: function () {
$(this).dialog("close");
callback(false);
}
}
});
$("#myAlert").parent().css('font-size', '9pt');
}
然后
confirm('some message', function (result) {
if (result) {}
})
演示:Fiddle