教程集 www.jiaochengji.com
教程集 >  jQuery  >  jquery 教程  >  正文 jquery封装的对话框简单实现

jquery封装的对话框简单实现

发布时间:2014-02-19   编辑:jiaochengji.com
本文为大家详细介绍下使用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 = "<div 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></div>";
return htmlStr;
}
function Alert(msg, okCallback) {
var title = "提示";
var type = "alert";
var html = dialogInit(type, msg);
var div = $("body").find("#"+type+"Div");
div.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 div = $("body").find("#"+type+"Div");
div.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 div = $("body").find("#"+type+"Div");
div.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 div = $("body").find("#"+type+"Div");
div.remove();
$('body').append($(html));

var buttons = {"确定" : function () {
if(okCallback) okCallback();
$(this).dialog("close");
}
};

$("#"+type+"Div").dialog({
modal : true,
title : title,
buttons : buttons
});

}

您可能感兴趣的文章:
jQuery Lightbox
jQuery对话框插件 akModal
jquery封装的对话框简单实现
jQuery Simple Dialog
基于jQuery架构javascript基础体系
jQuery插件教程
jQueryUI的Dialog的简单封装
【精品推荐】web开发人员应该知道的31个jQuery模态对话框
JQuery FlexiGrid的asp.net完美解决方案 dotNetFlexGrid-.Net原生的异步表格控件
Simple jQuery Modal Window

关键词: jquery  封装  对话框   
[关闭]
~ ~