对话框打开时将带有正确的标题和文本,并且当对话框关闭时,将成功调用clrflds()函数。但是,当对话框打开时,永远不会调用dialog_close()函数。我已经尝试了所有可以在网上找到的解决方案,但仍然存在问题。在此先感谢您的帮助
var returned = data;
if (returned == 0) {
$("#dialog_text").text("Login Failed");
$("#dialog_login").dialog({autoOpen: false});
$("#dialog_login").dialog({
title: "Login Status",
open: function(){
dialog_close()
},
close: function(){
clrflds()
}
});
$("#dialog_login").dialog("open");
//alert('Failed');;
}
else if (returned == 1) {
$('#login').load('m_insp_grid.html');
}
}
},
error: function(xhr, status, error){
alert(error);
}
});
}
function dialog_close(){
setTimeout(function(){$("#dialog_login").dialog("close");}, 3000);
}
function clrflds(){
$("#dept_id").val("");
$("#username").val("");
$("#pwd").val("");
}
答案 0 :(得分:0)
这是因为您在另一个上下文中,因为function(){...}。
我想,如果您编写console.log或alert而不是dialog_close();它被称为正确吗?
尝试写作:
open: () => {
dialog_close()
},
或
var that = this;
open: function() {
that.dialog_close()
}
也请参见此处:https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/