js实例教程-jquery封装的对话框简单实现方法

发布时间:2018-12-01 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了js实例教程-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=&#39;" + 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
});

}

代码如下:


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
});

}

觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦!&nbsp;js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的js实例教程-jquery封装的对话框简单实现方法全部内容,希望文章能够帮你解决js实例教程-jquery封装的对话框简单实现方法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。