function ValidateField(){
var bAllow= true;
//some checking here
if (bAllow == true && apl.val().trim() == "")
{
showDialog();
showDialog().done(function() {
return true; // wanna return true, but not success
}).fail(function() {
return false; //wanna return false, but not success
});
return false; //stop it to execute to next line
}
return bAllow; //success return }
function showDialog(){
var def = $.Deferred();
var modPop = '<div id="diaCom" title="Information?"><p>something something</p></div>';
$("#diaCom").remove();
$(modPop).appendTo('body');
$("#diaCom").dialog({
resizable: false,
draggable: false,
height:150,
width:300,
modal: true,
buttons: {
"Ok": function() {
def.resolve();
$(this).dialog("close");
},
"Cancel": function() {
def.reject();
$(this).dialog("close");
}
}
});
return def.promise();
}
//on click
if (validateField() == true){
//do something
}else{
//do something
}
大家好,有机会返还value吗?我希望通过 showDialog().done() 返回 true 和 false 并为 validatefield() 函数失败,但它不能按我想要的方式工作,我无法分配给 bAllow 因为我已经有一个 return false 可以保留执行下一行的对话框,知道吗?或者这样做是正确的?