转载出处:http://www.2ky.cn/Pri_upfile/txdemo/0811/zDialog/zDialogDemo.html
Dialog.open({URL:"test.html"});
var diag = new Dialog();
diag.Width = 600;
diag.Height = 300;
diag.Title = "设定了高宽和标题的普通窗口";
diag.URL = "test.html";
diag.show();
var diag = new Dialog();
diag.Width = 900;
diag.Height = 400;
diag.Title = "内容页为外部连接的窗口";
diag.URL = "http://demo.zving.com/";
diag.show();
var diag = new Dialog();
diag.Width = 300;
diag.Height = 100;
diag.Title = "内容页为html代码的窗口";
diag.InnerHtml='直接输出html,使用 InnerHtml 属性。'
diag.OKEvent = function(){diag.close();};//点击确定后调用的方法
diag.show();
var diag = new Dialog();
diag.Width = 300;
diag.Height = 150;
diag.Title = "内容页为隐藏的元素的html";
diag.InvokeElementId="forlogin"
diag.OKEvent = function(){$id("username").value||Dialog.alert("用户名不能为空");$id("userpwd").value||Dialog.alert("密码不能为空")};//点击确定后调用的方法
diag.show();
var diag = new Dialog();
diag.Modal = false;
diag.Title = "弹出没有遮罩层的窗口";
diag.URL = "test.html";
diag.show();
关闭窗口按钮代码: Dialog.close();
var diag = new Dialog();
diag.Width = 200;
diag.Height = 100;
diag.Modal = false;
diag.Title = "在指定位置弹出窗口";
diag.Top="100%";
diag.Left="100%";
diag.URL = "test.html";
diag.show();
注:可使用数字或百分比(带百分比符号的字符串)来定义相对于当前窗口的位置,换算效果同css中用百分比定义背景图位置,如Left:”0%”,Top:”0%”为左上,Left:”50%”,Top:”50%”为居中,Left:”100%”,Top:”100%”为右下。
var diag = new Dialog();
diag.Title = "返回值到调用页面";
diag.URL = "test.html";
diag.OKEvent = function(){$id('getval').value = diag.innerFrame.contentWindow.document.getElementById('a').value;diag.close();};
diag.show();
var doc=diag.innerFrame.contentWindow.document;
doc.open();
doc.write('请在文本框里输入一些值') ;
doc.close();
Dialog.alert("提示:你点击了一个按钮");
Dialog.confirm('警告:您确认要XXOO吗?',function(){Dialog.alert("yeah,周末到了,正是好时候")});
注:Dialog.alert(msg, func, w, h)第二个参数为点击“确定”按钮后执行的函数。
Dialog.confirm(msg, funcOK, funcCal, w, h)第二个参数为点击“确定”按钮后执行的函数,第三个参数为点击“取消”按钮后执行的函数。
var diag = new Dialog();
diag.Title = "创建其它按钮";
diag.URL = "test.html";
diag.show();
diag.addButton("next","下一步",function(){
var doc=diag.innerFrame.contentWindow.document;
doc.open();
doc.write('进入了下一步') ;
doc.close();
})
var diag = new Dialog();
diag.Title = "带有说明栏的新窗口";
diag.Width = 900;
diag.Height = 400;
diag.URL = "http://demo.zving.com/";
diag.MessageTitle = "泽元网站内容管理系统";
diag.Message = "泽元网站内容管理系统是一个基于J2EE及AJAX技术的企业级网站内容管理系统";
diag.show();
var diag = new Dialog();
diag.URL = "http://demo.zving.com/";
diag.show();
注:如果窗体内为iframe内容页,并且没有设置Title属性,并且引用页和当前页在同一个域内,则显示显示窗体内容页面标题。
var diag = new Dialog();
diag.OnLoad=function(){alert("页面载入完成")};
diag.URL = "http://demo.zving.com/";
diag.show();
注:如果窗体内为iframe内容页,要在载入完成后对内容页作操作,必须考虑访问权限,如引用页和当前页应在同一个域内。
var diag = new Dialog();
diag.Title = "点击取消或关闭按钮时执行方法";
diag.CancelEvent=function(){alert("点击取消或关闭按钮时执行方法");diag.close();};
diag.URL = "test.html";
diag.show();
var diag = new Dialog();
diag.Drag=false;
diag.URL = "test.html";
diag.show();
var diag = new Dialog();
diag.Title = "修改中窗体尺寸";
diag.URL = "javascript:void(document.write(\'这是弹出窗口中的内容\'))";
diag.OKEvent = function(){
var doc=diag.innerFrame.contentWindow.document;
doc.open();
doc.write('窗口尺寸改为600*300') ;
doc.close();
diag.setSize(600,300);
};
diag.show();
diag.okButton.value="改变窗口大小"
var diag = new Dialog();
diag.AutoClose=5;
diag.ShowCloseButton=false;
diag.URL = "javascript:void(document.write(\'这是弹出窗口中的内容\'))";
diag.show();
注:AutoClose为自动关闭时间,单位秒
var diag = new Dialog();
diag.Title="设置确定按钮及取消按钮的属性";
diag.ShowButtonRow=true;
diag.URL = "test.html";
diag.show();
diag.okButton.value=" OK ";
diag.cancelButton.value="Cancel";
var diag = new Dialog();
diag.Title = "窗体内的按钮操作父Dialog";
diag.URL = "test.html";
diag.show();
var doc=diag.innerFrame.contentWindow.document;
doc.open();
doc.write('type="button" id="a" value="修改父Dialog尺寸" \
οnclick="parentDialog.setSize(function(min,max){return Math.round(min+(Math.random()*(max-min)))}(300,800))" \
/>type="button" id="b" value="关闭父窗口" οnclick="parentDialog.close()" />') ;
doc.close();
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script
src=' '
type="text/javascript" charset="utf-8">script>
<script
src=' '
type="text/javascript" charset="utf-8">script>
<script
src=' '
type="text/javascript" charset="utf-8">script>
<title>Insert title heretitle>
head>
<body>
<input type="button" value="普通窗口" name="btn1" id="btn1" onclick="open_1()"/>
<input type="button" value="设定了高宽和标题的普通窗口" name="btn2" id="btn2" onclick="open_2()"/>
<input type="button" value="内容页为外部链接窗口" name="btn3" id="btn3" onclick="open_3()"/>
<input type="button" value="内容为html代码的窗口" name="btn4" id="btn4" onclick="open_4()"/>
<input type="button" value="内容页为隐藏的元素的html内容" name="btn5" id="btn5" onclick="open_5()"/>
<div id="forlogin">
<table width="100%" border="0" align="center" cellpadding="4" cellspacing="4" bordercolor="#666666">
<tr>
<td colspan="2" bgcolor="#eeeeee">用户登陆td>
tr>
<tr>
<td width="50" align="right">用户名td>
<td><input type="text" id="username" />td>
tr>
<tr>
<td align="right">密 码td>
<td><input type="text" id="userpwd" />td>
tr>
table>
div>
div>
<input type="button" value="弹出没有遮罩层的窗口" name="btn6" id="btn6" onclick="open_6()"/>
<input type="button" value="在指定位置弹出窗口" name="btn7" id="btn7" onclick="open_7()"/>
<input type="button" value="返回值到调用页面" name="btn8" id="btn8" onclick="open_8()"/>
<input type="text" id="getval" value="" placeholder="回调的值"/>
<br><br>
<input type="button" value="代替window.alert窗口" name="btn9" id="btn9" onclick="open_9()"/>
<input type="button" value="代替window.confirm窗口" name="btn10" id="btn10" onclick="open_10()"/>
<input type="button" value="创建其他按钮窗口" name="btn11" id="btn11" onclick="open_11()"/>
<input type="button" value="弹出带说明栏的窗口" name="btn12" id="btn12" onclick="open_12()"/>
<input type="button" value="在弹窗的内容载入完成后,执行方法窗口" name="btn13" id="btn13" onclick="open_13()"/>
<br><br>
<input type="button" value="点击取消及关闭时执行方法窗口" name="btn14" id="btn14" onclick="open_14()"/>
<input type="button" value="不允许拖拽窗口" name="btn15" id="btn15" onclick="open_15()"/>
<input type="button" value="动态改变窗口大小" name="btn16" id="btn16" onclick="open_16()"/>
<input type="button" value="弹出窗口自动关闭" name="btn17" id="btn17" onclick="open_17()"/>
<input type="button" value="设置确定按钮及取消按钮的属性" name="btn18" id="btn18" onclick="open_18()"/>
<input type="button" value="窗体内的按钮操作父Dialog" name="btn19" id="btn19" onclick="open_19()"/>
body>
<script type="text/javascript">
$("#forlogin").hide();
function open_1(){
Dialog.open({URL:"test.jsp"});
}
function open_2(){
var diag = new Dialog();
diag.Width = 600;
diag.Height = 300;
diag.Title = "设定了高宽和标题的普通窗口";
diag.URL = "test.jsp";
diag.show();
}
function open_3(){
var diag = new Dialog();
diag.Width = 900;
diag.Height = 400;
diag.Title = "内容页为外部链接窗口";
diag.URL = "http://www.baidu.com";
diag.show();
}
function open_4(){
var diag = new Dialog();
diag.Width = 300;
diag.Height = 100;
diag.Title = "内容为html代码的窗口";
diag.InnerHtml = '直接输出html,使用 InnerHtml 属性。'
diag.OKEvent = function(){
diag.close(); // 点击确定后调用的方法
};
diag.show();
}
function open_5(){
var diag = new Dialog();
diag.Width = 300;
diag.Height = 100;
diag.Title = "内容页为隐藏的元素的html";
diag.InvokeElementId="forlogin"
diag.OKEvent = function(){$id("username").value||Dialog.alert("用户名不能为空");$id("userpwd").value||Dialog.alert("密码不能为空")};//点击确定后调用的方法
diag.show();
}
function open_6(){
var diag = new Dialog();
diag.Modal = false;
diag.Title = "弹出没有遮罩层的窗口";
diag.URL = "test.jsp";
diag.show();
}
function open_7(){
var diag = new Dialog();
diag.Width = 200;
diag.Height = 100;
diag.Modal = false;
diag.Title = "在指定位置弹出窗口";
diag.Top="100%";
diag.Left="100%";
diag.URL = "test.jsp";
//注:可使用数字或百分比(带百分比符号的字符串)来定义相对于当前窗口的位置,换算效果同css中用百分比定义背景图位置,如Left:"0%",Top:"0%"为左上,Left:"50%",Top:"50%"为居中,Left:"100%",Top:"100%"为右下。
diag.show();
}
function open_8(){
var diag = new Dialog();
diag.Title = "返回值到调用页面";
diag.URL = "test.jsp";
diag.OKEvent = function(){
$id('getval').value = diag.innerFrame.contentWindow.document.getElementById('a').value;
diag.close();
};
diag.show();
var doc=diag.innerFrame.contentWindow.document;
doc.open();
doc.write('请在文本框里输入一些值') ;
doc.close();
}
function open_9(){
// Dialog.alert(msg, func, w, h)第二个参数为点击“确定”按钮后执行的函数。
Dialog.alert("提示:你点击了一个按钮!");
}
function open_10(){
// Dialog.confirm(msg, funcOK, funcCal, w, h)第二个参数为点击“确定”按钮后执行的函数,第三个参数为点击“取消”按钮后执行的函数。
Dialog.confirm('警告:您确认要XXOO吗?',function(){Dialog.alert("yeah,周末到了,正是好时候")});
}
function open_11(){
var diag = new Dialog();
diag.Title = "创建其它按钮";
diag.URL = "test.jsp";
diag.show();
diag.addButton("next","下一步",function(){
var doc=diag.innerFrame.contentWindow.document;
doc.open();
doc.write('进入了下一步') ;
doc.close();
});
}
function open_12(){
var diag = new Dialog();
diag.Title = "带有说明栏的新窗口";
diag.Width = 900;
diag.Height = 400;
diag.URL = "http://demo.zving.com/";
diag.MessageTitle = "泽元网站内容管理系统";
diag.Message = "泽元网站内容管理系统是一个基于J2EE及AJAX技术的企业级网站内容管理系统";
diag.show();
}
function open_13(){
var diag = new Dialog();
diag.OnLoad=function(){
alert("页面载入完成");
};
diag.URL = "http://demo.zving.com/";
diag.show();
}
function open_14(){
var diag = new Dialog();
diag.Title = "点击取消或关闭按钮时执行方法";
diag.CancelEvent=function(){
alert("点击取消或关闭按钮时执行方法");
diag.close();
};
diag.URL = "test.jsp";
diag.show();
}
function open_15(){
var diag = new Dialog();
diag.Drag = false;
diag.URL = "test.jsp";
diag.show();
}
function open_16(){
var diag = new Dialog();
diag.Title = "修改中窗体尺寸";
diag.URL = "javascript:void(document.write(\'这是弹出窗口中的内容\'))";
diag.OKEvent = function(){
var doc=diag.innerFrame.contentWindow.document;
doc.open();
doc.write('窗口尺寸改为600*300') ;
doc.close();
diag.setSize(600,300);
};
diag.show();
diag.okButton.value="改变窗口大小"
}
function open_17(){
var diag = new Dialog();
diag.AutoClose=5;
diag.ShowCloseButton=false;
diag.URL = "javascript:void(document.write(\'这是弹出窗口中的内容\'))";
diag.show();
}
function open_18(){
var diag = new Dialog();
diag.Title="设置确定按钮及取消按钮的属性";
diag.ShowButtonRow=true;
diag.URL = "test.jsp";
diag.show();
diag.okButton.value=" OK ";
diag.cancelButton.value="Cancel";
}
function open_19(){
var diag = new Dialog();
diag.Title = "窗体内的按钮操作父Dialog";
diag.URL = "test.jsp";
diag.show();
var doc=diag.innerFrame.contentWindow.document;
doc.open();
doc.write('') ;
doc.close();
}
script>
html>
注意:
导入的js:
修改zDialog.js中图标的文件位置: