内建对话框
用法 var a=new NLAlertDialog('"NLAlertDialog"');
a.show('title','sMessage',3)
----------------------------------------------------------------------
function hideAlertBox(elemId)
{
document.getElementById(elemId).style.display='none';
}
function getAlertBoxHtml(sTitle, sMessage, iType, width, helpUrl, helpText)
{
if (iType != NLAlertDialog.TYPE_LOWEST_PRIORITY &&
iType != NLAlertDialog.TYPE_LOW_PRIORITY &&
iType != NLAlertDialog.TYPE_MEDIUM_PRIORITY &&
iType != NLAlertDialog.TYPE_HIGH_PRIORITY)
iType = NLAlertDialog.TYPE_LOW_PRIORITY;
if(!width)
width = 600;
if (!sTitle)
{
switch (iType)
{
case NLAlertDialog.TYPE_LOWEST_PRIORITY:
sTitle = "Confirmation";
break;
case NLAlertDialog.TYPE_LOW_PRIORITY:
sTitle = "Information";
break;
case NLAlertDialog.TYPE_MEDIUM_PRIORITY:
sTitle = "WARNING";
break;
case NLAlertDialog.TYPE_HIGH_PRIORITY:
default:
sTitle = "Error";
break;
}
}
var bHelpLink = false;
if (helpUrl && helpUrl.length > 0)
{
bHelpLink = true;
if (!helpText)
helpText = "Visit this Help Topic";
}
return "<table cellpadding=8><tr><td><table cellpadding=0 cellspacing=0 border=0 width=" + width + " style='font-family: Verdana,Helvetica,sans-serif; font-size: 11px; width:" + width + ";'>"+
"<tr>"+
"<td valign=top rowspan=3 style='background-image: url(/images/icons/reporting/mbx2_box_l.gif)'><img src='/images/icons/reporting/mbx2_box_ul_type" + iType + ".gif' width=8 height=8 border=0></td>"+
"<td valign=top rowspan=3><img src='/images/icons/reporting/mbx2_icontop_type" + iType + ".gif' width=45 height=22 border=0></td>"+
"<td style='background-color: #E2E2E2' height='1' width='100%'><img src='/images/icons/reporting/x.gif' width=1 height=1></td>"+
"<td bgcolor='" + ((iType <= NLAlertDialog.TYPE_MEDIUM_PRIORITY) ? "#E5E5E5" : "#F6BFBF") + "' valign=top rowspan=3><img src='/images/icons/reporting/mbx2_box_ur_type" + iType + ".gif' width=8 height=8 border=0></td>"+
"</tr>"+
"<tr>"+
"<td bgcolor='" + ((iType <= NLAlertDialog.TYPE_MEDIUM_PRIORITY) ? "#F6F6F6" : "#FAD9D9") + "' height=1><img src='/images/icons/reporting/x.gif' width=1 height=1></td>"+
"</tr>"+
"<tr>"+
"<td bgcolor='" + ((iType <= NLAlertDialog.TYPE_MEDIUM_PRIORITY) ? "#E5E5E5" : "#F6BFBF") + "' height=16><b>"+sTitle+"</b></td>"+
"</tr>"+
"<tr>"+
"<td style='background-image: url(/images/icons/reporting/mbx2_box_l.gif)'></td>"+
"<td valign=top bgcolor='#FFFFFF'><img src='/images/icons/reporting/mbx2_iconbot_type" + iType + ".gif' width=45 height=18 border=0></td>"+
"<td style='background-color:#FFFFFF; font-weight:normal; padding-top:3px;'>"+sMessage +
( (bHelpLink) ?
("<p align='right'> <img height='17' src='/images/icons/help/icon_help_green.gif' width='17' style='vertical-align:middle' /> <a href=\"" + helpUrl.replace(/"/g, """) + "\">" + helpText + "</a></p>") :"") +
"</td>"+
"<td style='background-image: url(/images/icons/reporting/mbx2_box_r.gif)'></td>"+
"</tr>"+
"<tr>"+
"<td valign=top><img src='/images/icons/reporting/mbx2_box_ll.gif' width=8 height=8 border=0></td>"+
"<td style='background-image: url(/images/icons/reporting/mbx2_box_b.gif)' colspan=2><img src='/images/icons/reporting/x.gif' width=1 height=8></td>"+
"<td valign=bottom><img src='/images/icons/reporting/mbx2_box_lr.gif' width=8 height=8 border=0></td>"+
"</tr>"+
"</table></td></tr></table>";
}
NLAlertDialog = Class.create();
NLAlertDialog.TYPE_LOWEST_PRIORITY = 0;
NLAlertDialog.TYPE_LOW_PRIORITY = 1;
NLAlertDialog.TYPE_MEDIUM_PRIORITY = 2;
NLAlertDialog.TYPE_HIGH_PRIORITY = 3;
NLAlertDialog.prototype =
{
initialize: function(sId)
{
this.sId = sId || "NLAlertDialog";
},
show: function(sTitle, sMessage, iType, sTargetDivId)
{
var posX = document.body.clientWidth / 2;
var posY = document.body.clientHeight / 2;
var sTitleId = this.sId + '_title';
var sMessageId = this.sId + '_message';
if(!iType) iType = NLAlertDialog.TYPE_LOW_PRIORITY;
if (!this.hndDialogDiv)
{
this.hndDialogDiv = document.createElement("div");
this.hndDialogDiv.innerHTML = getAlertBoxHtml(sTitle, sMessage, iType);
this.hndDialogDiv.style.display = "none";
this.hndDialogDiv.style.position = "absolute";
document.body.appendChild(this.hndDialogDiv);
}
if (sTargetDivId != null)
{
$(sTargetDivId).innerHTML = this.hndDialogDiv.innerHTML;
return;
}
if (this.hndDialogDiv.style.display == "block")
return;
this.hndDialogDiv.style.display = "block";
this.hndDialogDiv.style.top = posY - (this.hndDialogDiv.clientHeight / 2);
this.hndDialogDiv.style.left = posX - (this.hndDialogDiv.clientWidth / 2);
},
hide: function( sTargetDivId )
{
if (sTargetDivId != null)
$(sTargetDivId).innerHTML = "";
else if (this.hndDialogDiv != null)
this.hndDialogDiv.style.display = "none";
}
}
本文来自博客园,作者:CarlZeng,转载请注明原文链接:https://www.cnblogs.com/backuper/archive/2009/07/16/1524838.html
需求沟通链接 扫客服加群:

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话