Discuz!大师网

搜索
查看: 1154|回复: 0

Discuz!开发之js弹出框函数showDialog介绍

[复制链接]
发表于 2017-4-9 01:09:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
showDialog定义地址:\static\js\common.js
  1. var showDialogST = null;
  2. function showDialog(msg, mode, t, func, cover, funccancel, leftmsg, confirmtxt, canceltxt, closetime, locationtime) {
  3.         clearTimeout(showDialogST);
  4.         cover = isUndefined(cover) ? (mode == 'info' ? 0 : 1) : cover;
  5.         leftmsg = isUndefined(leftmsg) ? '' : leftmsg;
  6.         mode = in_array(mode, ['confirm', 'notice', 'info', 'right']) ? mode : 'alert';
  7.         var menuid = 'fwin_dialog';
  8.         var menuObj = $(menuid);
  9.         var showconfirm = 1;
  10.         confirmtxtdefault = '确定';
  11.         closetime = isUndefined(closetime) ? '' : closetime;
  12.         closefunc = function () {
  13.                 if(typeof func == 'function') func();
  14.                 else eval(func);
  15.                 hideMenu(menuid, 'dialog');
  16.         };
  17.         if(closetime) {
  18.                 showPrompt(null, null, '<i>' + msg + '</i>', closetime * 1000, 'popuptext');
  19.                 return;
  20.         }
  21.         locationtime = isUndefined(locationtime) ? '' : locationtime;
  22.         if(locationtime) {
  23.                 leftmsg = locationtime + ' 秒后页面跳转';
  24.                 showDialogST = setTimeout(closefunc, locationtime * 1000);
  25.                 showconfirm = 0;
  26.         }
  27.         confirmtxt = confirmtxt ? confirmtxt : confirmtxtdefault;
  28.         canceltxt = canceltxt ? canceltxt : '取消';

  29.         if(menuObj) hideMenu('fwin_dialog', 'dialog');
  30.         menuObj = document.createElement('div');
  31.         menuObj.style.display = 'none';
  32.         menuObj.className = 'fwinmask';
  33.         menuObj.id = menuid;
  34.         $('append_parent').appendChild(menuObj);
  35.         var hidedom = '';
  36.         if(!BROWSER.ie) {
  37.                 hidedom = '<style type="text/css">object{visibility:hidden;}</style>';
  38.         }
  39.         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>';
  40.         s += t ? t : '提示信息';
  41.         s += '</em><span><a href="javascript:;" id="fwin_dialog_close" class="flbc" onclick="hideMenu(\'' + menuid + '\', \'dialog\')" title="关闭">关闭</a></span></h3>';
  42.         if(mode == 'info') {
  43.                 s += msg ? msg : '';
  44.         } else {
  45.                 s += '<div class="c altw"><div class="' + (mode == 'alert' ? 'alert_error' : (mode == 'right' ? 'alert_right' : 'alert_info')) + '"><p>' + msg + '</p></div></div>';
  46.                 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>' : '');
  47.                 s += mode == 'confirm' ? '<button id="fwin_dialog_cancel" value="true" class="pn" onclick="hideMenu(\'' + menuid + '\', \'dialog\')"><strong>'+canceltxt+'</strong></button>' : '';
  48.                 s += '</p>';
  49.         }
  50.         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>';
  51.         menuObj.innerHTML = s;
  52.         if($('fwin_dialog_submit')) $('fwin_dialog_submit').onclick = function() {
  53.                 if(typeof func == 'function') func();
  54.                 else eval(func);
  55.                 hideMenu(menuid, 'dialog');
  56.         };
  57.         if($('fwin_dialog_cancel')) {
  58.                 $('fwin_dialog_cancel').onclick = function() {
  59.                         if(typeof funccancel == 'function') funccancel();
  60.                         else eval(funccancel);
  61.                         hideMenu(menuid, 'dialog');
  62.                 };
  63.                 $('fwin_dialog_close').onclick = $('fwin_dialog_cancel').onclick;
  64.         }
  65.         showMenu({'mtype':'dialog','menuid':menuid,'duration':3,'pos':'00','zindex':JSMENU['zIndex']['dialog'],'cache':0,'cover':cover});
  66.         try {
  67.                 if($('fwin_dialog_submit')) $('fwin_dialog_submit').focus();
  68.         } catch(e) {}
  69. }
复制代码

参数意义:
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>
回复 马甲回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|网站地图|小黑屋|展会网|Discuz站长论坛 |天天打卡

GMT+8, 2024-4-26 07:53 , Processed in 0.023247 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表