<!-- 在人才招聘网上出现的模态窗口,可以用简单的JS 代码的实现,需要两个页面,一个是父页面,一个是子页面。-->
父页面:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>父页面</title>
<script type="text/javascript">
function openstr()
{
window.open("b.html","","modal=yes,width=500,height=500,resizable=no,scrollbars=no");
}
function openkk(){
var kk = window.showModalDialog("b.html");
document.getElementById('texts').value = kk;
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="txtselect" id="txtselect">
</select>
</label>
<label>
<input type="button" name="Submit" value="打开子窗口" onclick="openstr()" />
<input type="button" name="Submit" value="打开模态窗口" onclick="openkk()"/>
<input type="text" id = "texts">
</label>
</form>
</body>
子页面:
<title>子页面</title>
<script type="text/javascript">
function clickok2(){
var color = document.getElementById('color').value;
window.returnValue = color;
window.close();
}
function ClickOk()
{
var t=document.Edit;
var color=t.color.value;
if(color==null||color=="填写颜色") return(false);
var oOption = window.opener.document.createElement('OPTION');
oOption.text=document.getElementById("color").value;
oOption.value=document.getElementById("color").value;
//检查浏览器类型
var bname = navigator.appName;
if (bname.search(/netscape/i) == 0)
{
window.opener.document.getElementById("txtselect").appendChild(oOption);
}
else if (bname.search(/microsoft/i) == 0)
{
window.opener.document.all.txtselect.add(oOption);
}
else
{
}
window.close();
}
</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="2" align="center" width="300">
<form name="Edit" id="Edit">
<tr>
<td width="30" align="right" height="30">color:</td>
<td height="30"><input type="text" name="color" id="color" value="填写颜色" /></td>
<td width="56" align="center" height="30"><input " type="button" name="bntOk" value="确认" onclick="ClickOk();" />
<input type="button" value="模态传值" onclick="clickok2()"/>
</td>
</tr>
</form>
</table>
</body>