Discuz!开发之js弹出框函数showDialog介绍 [复制链接]

moqu8 2018-5-1

1872 0
showDialog定义地址:\static\js\common.js
var showDialogST = null;  
function showDialog(msg, mode, t, func, cover, funccancel, leftmsg, confirmtxt, canceltxt, closetime, locationtime) {
clearTimeout(showDialogST);
cover = isUndefined(cover) ? (mode == 'info' ? 0 : 1) : cover;
leftmsg = isUndefined(leftmsg) ? '' : leftmsg;
mode = in_array(mode, ['confirm', 'notice', 'info', 'right']) ? mode : 'alert';
var menuid = 'fwin_dialog';
var menuObj = $(menuid);
var showconfirm = 1;
confirmtxtdefault = '确定';
closetime = isUndefined(closetime) ? '' : closetime;
closefunc = function () {
if(typeof func == 'function') func();
else eval(func);
hideMenu(menuid, 'dialog');
};
if(closetime) {
showPrompt(null, null, '<i>' + msg + '</i>', closetime * 1000, 'popuptext');
return;
}
locationtime = isUndefined(locationtime) ? '' : locationtime;
if(locationtime) {
leftmsg = locationtime + ' 秒后页面跳转';
showDialogST = setTimeout(closefunc, locationtime * 1000);
showconfirm = 0;
}
confirmtxt = confirmtxt ? confirmtxt : confirmtxtdefault;
canceltxt = canceltxt ? canceltxt : '取消';


if(menuObj) hideMenu('fwin_dialog', 'dialog');
menuObj = document.createElement('div');
menuObj.style.display = 'none';
menuObj.className = 'fwinmask';
menuObj.id = menuid;
$('append_parent').appendChild(menuObj);
var hidedom = '';
if(!BROWSER.ie) {
hidedom = '<style type="text/css">object{visibility:hidden;}</style>';
}
var s = hidedom + '<table cellpadding="0" cellspacing="0" class="fwin"><tr><td class="t_l"></td><td class="t_c"></td><td class="t_r"></td></tr><tr><td class="m_l"> </td><td class="m_c"><h3 class="flb"><em>';
s += t ? t : '提示信息';
s += '</em><span><a href="javascript:;" id="fwin_dialog_close" class="flbc" onclick="hideMenu(\'' + menuid + '\', \'dialog\')" title="关闭">关闭</a></span></h3>';
if(mode == 'info') {
s += msg ? msg : '';
} else {
s += '<div class="c altw"><div class="' + (mode == 'alert' ? 'alert_error' : (mode == 'right' ? 'alert_right' : 'alert_info')) + '"><p>' + msg + '</p></div></div>';
s += '<p class="o pns">' + (leftmsg ? '<span class="z xg1">' + leftmsg + '</span>' : '') + (showconfirm ? '<button id="fwin_dialog_submit" value="true" class="pn pnc"><strong>'+confirmtxt+'</strong></button>' : '');
s += mode == 'confirm' ? '<button id="fwin_dialog_cancel" value="true" class="pn" onclick="hideMenu(\'' + menuid + '\', \'dialog\')"><strong>'+canceltxt+'</strong></button>' : '';
s += '</p>';
}
s += '</td><td class="m_r"></td></tr><tr><td class="b_l"></td><td class="b_c"></td><td class="b_r"></td></tr></table>';
menuObj.innerHTML = s;
if($('fwin_dialog_submit')) $('fwin_dialog_submit').onclick = function() {
if(typeof func == 'function') func();
else eval(func);
hideMenu(menuid, 'dialog');
};
if($('fwin_dialog_cancel')) {
$('fwin_dialog_cancel').onclick = function() {
if(typeof funccancel == 'function') funccancel();
else eval(funccancel);
hideMenu(menuid, 'dialog');
};
$('fwin_dialog_close').onclick = $('fwin_dialog_cancel').onclick;
}
showMenu({'mtype':'dialog','menuid':menuid,'duration':3,'pos':'00','zindex':JSMENU['zIndex']['dialog'],'cache':0,'cover':cover});
try {
if($('fwin_dialog_submit')) $('fwin_dialog_submit').focus();
} catch(e) {}
}


参数意义:
showDialog(msg, mode, t, func, cover)
msg:内容,支持html
mode:提升模式,从函数里面看,支持'confirm'(显示确定,取消按钮), 'notice'(显示确定按钮), 'info'(只有内容,除了关闭标志,没有任何按钮),这几个mod如果没有被定义,默认使用alert,也就是错误提示,显示一个X再加一个确定按钮
t:也就是title,留空会使用“提示信息”着四个字
func:点击fwin_dialog_submit,也就是确定按钮的时候执行的动作,如果用typeof 检查结果是一个函数,就执行之,不用请填写NULL
cover:使用背景遮罩


使用实例:
<div id=”divajax”></div>
<p><a href=”result.php” onclick=”showWindow('test',this.href);return false;”>显示一个浮动窗口来返回ajax结果,这里用到了showWindow函数</a></p>
<a href=”javascript:;” onclick=”showDialog('演示document.write()!', 'confirm', '演示', 'document.write (\'演示document.write()\')',1)”>document.write</a>
<a href=”javascript:;” onclick=”showDialog('演示location.href()!', 'confirm', '演示', 'parent.location.href=\'http://g.cn\”,1)”>location.href</a>
<a href=”javascript:;” onclick=”showDialog('演示ajaxget(),输出到id=divajax的这一层里面', 'confirm', '演示', 'ajaxget(\'result.php?\',\'divajax\')', 1)”>ajaxget</a>


最新回复 (0)
返回
支持中心
邮箱:winkill2012@qqcom
新站优化中!部分功能尚未完善,敬请谅解!
支持中心