zl程序教程

您现在的位置是:首页 >  前端

当前栏目

jquery封装的对话框简单实现

jQuery封装 实现 简单 对话框
2023-06-13 09:15:03 时间
复制代码代码如下:

var_alert_iconCss="tipmsg_icoInfo";
var_confirm_iconCss="tipmsg_icoConfirm";
var_error_iconCss="tipmsg_icoError";
var_warning_iconCss="tipmsg_icoWarning";
functiondialogInit(type,msg){
variconCss="";
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;
}

varhtmlStr="<divid=""+type+"Div"style="display:none;"><p><spanclass=""+iconCss+""style="float:left;margin:07px50px0;width:35px;height:35px;"></span>"+msg+"</p></div>";
returnhtmlStr;
}
functionAlert(msg,okCallback){
vartitle="提示";
vartype="alert";
varhtml=dialogInit(type,msg);
vardiv=$("body").find("#"+type+"Div");
div.remove();
$("body").append($(html));

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

$("#"+type+"Div").dialog({
modal:true,
title:title,
buttons:buttons
});
}
functionConfirm(msg,okCallback,cancelCallback){
vartitle="确认";
vartype="confirm";
varhtml=dialogInit(type,msg);
vardiv=$("body").find("#"+type+"Div");
div.remove();
$("body").append($(html));

varbuttons={"确定":function(){
if(okCallback)okCallback();
$(this).dialog("close");
},
"取消":function(){
if(cancelCallback)cancelCallback();
$(this).dialog("close");
}
};
$("#"+type+"Div").dialog({
modal:true,
title:title,
buttons:buttons
});
}
functionError(msg,okCallback){
vartitle="错误";
vartype="error";
varhtml=dialogInit(type,msg);
vardiv=$("body").find("#"+type+"Div");
div.remove();
$("body").append($(html));

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

$("#"+type+"Div").dialog({
modal:true,
title:title,
buttons:buttons
});
}
functionWarning(msg,okCallback){
vartitle="警告";
vartype="warning";
varhtml=dialogInit(type,msg);
vardiv=$("body").find("#"+type+"Div");
div.remove();
$("body").append($(html));

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

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

}