jquery封装的对话框简单实现方法
代码如下:
var _alert_iconcss = "tipmsg_icoinfo";
var _confirm_iconcss = "tipmsg_icoconfirm";
var _error_iconcss = "tipmsg_icoerror";
var _warning_iconcss = "tipmsg_icowarning";
function dialoginit(type, msg) {
var iconcss = "";
switch (type) {
case "confirm" : iconcss = _confirm_iconcss; break;
case "error" : iconcss = _error_iconcss; break;
case "warning" : iconcss = _warning_iconcss; break;
default : iconcss = _alert_iconcss; break;
}
var htmlstr = "<p id='" + type + "div' style='display: none;'><p><span class='" + iconcss + "' style='float:left; margin:0 7px 50px 0;width:35px;height:35px;'></span>" + msg + "</p></p>";
return htmlstr;
}
function alert(msg, okcallback) {
var title = "提示";
var type = "alert";
var html = dialoginit(type, msg);
var p = $("body").find("#"+type+"div");
p.remove();
$('body').append($(html));
var buttons = {"确定" : function () {
if(okcallback) okcallback();
$(this).dialog("close");
}
};
$("#"+type+"div").dialog({
modal : true,
title : title,
buttons : buttons
});
}
function confirm(msg, okcallback, cancelcallback) {
var title = "确认";
var type = "confirm";
var html = dialoginit(type, msg);
var p = $("body").find("#"+type+"div");
p.remove();
$('body').append($(html));
var buttons = {"确定" : function () {
if(okcallback) okcallback();
$(this).dialog("close");
},
"取消" : function () {
if(cancelcallback) cancelcallback();
$(this).dialog("close");
}
};
$("#"+type+"div").dialog({
modal : true,
title : title,
buttons : buttons
});
}
function error(msg, okcallback) {
var title = "错误";
var type = "error";
var html = dialoginit(type, msg);
var p = $("body").find("#"+type+"div");
p.remove();
$('body').append($(html));
var buttons = {"确定" : function () {
if(okcallback) okcallback();
$(this).dialog("close");
}
};
$("#"+type+"div").dialog({
modal : true,
title : title,
buttons : buttons
});
}
function warning(msg, okcallback) {
var title = "警告";
var type = "warning";
var html = dialoginit(type, msg);
var p = $("body").find("#"+type+"div");
p.remove();
$('body').append($(html));
var buttons = {"确定" : function () {
if(okcallback) okcallback();
$(this).dialog("close");
}
};
$("#"+type+"div").dialog({
modal : true,
title : title,
buttons : buttons
});
}