<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Page Title</title>\
<script type="text/javascript">
var userName="";
function fnCallDialog(){
//showModalDialog 谷歌火狐没有这个函数,测试IE可用用
showModalDialog("myDialog.html",window);
}
function updateDialog(){
var _p=document.getElementById('_name');
_p.firstChild.nodeValue=userName;
}
window.function(){
first();
//second();
}
function first(){
alert('欢迎您的访问,请按"确定"继续!');
//确认对话框
var cf=window.confirm("请选择一个按钮!");
if(cf){
alert("你单击了确定按钮");
}else{
alert("你单击了取消按钮");
}
//提示对话框
var msg=prompt("请输入姓名:","请在此输入信息");
if(msg!=null){
if(msg=='请在此输入信息'){
alert("你没有输入信息");
}else{
alert("你输入的信息:"+msg);
}
}else{
alert("你取消了输入!")
}
}
</script>
</head>
<body>
<p>输入的用户名是:
<span id="_name">UWKS</span>
</p>
<input type="button" value="打开对话框" onclick="javascript:fnCallDialog()">
</body>
</html>
myDialog.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Page Title</title>
<script>
function fnGetInfo(){
var sWindow=window.dialogArguments;
// alert(sWindow);
var oName=document.getElementById('oUserName');
sWindow.userName=oName.value;
sWindow.updateDialog();
}
function fnCancel(){
var sWindow=window.dialogArguments;
sWindow.userName="你没有输入";
sWindow.updateDialog();
}
</script>
</head>
<label for="oUserName">请输入姓名:</label>
<input id="oUserName"/>
<input type="button" value="确定" onclick="javascript:fnGetInfo();window.close();"/>
<input type="button" value="取消" onclick="javascript:fnCancel();window.close();"/>
<body>
</body>
</html>