一、即时传值,即在窗口中点击某项数据时把值传给父窗口
父窗口:p.html
<body>
<input type="txt" id="txtid"/> <a href="javascript:" οnclick="SelectUser()">选择</a>
</body>
<script>
function SelectUser()
{
URL="/admin/member/select_member.aspx";
/*-----------------------判断浏览器------------*/
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
loc_y=loc_x=200;//模态窗口定位
if(is_ie)
{
loc_x=document.body.scrollLeft+event.clientX-100;
loc_y=document.body.scrollTop+event.clientY+170;
}
//弹出模态窗口 window.showModalDialog(URL,self,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:"+400+"px;dialogHeight:"+350+"px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px",true);
}
function clearuser()
{
document.getElementById("txtid").value="";
}
</script>
子窗口页面:
<table class="TableList" width="100%" align="center">
<tr class="TableData">
<td class="lefttd">
部门名称
</td>
<td style="text-align: left;" id="td1" οnclick="selectvalue()">
开发部
</td>
</tr>
</table>
<script language="javascript" type="text/javascript">
function selectvalue()
{
var pobj = window.dialogArguments; //获得父窗口文本框对象
pobj.document.all["txtid"].value+=document.getElementById("td1").innerHTML;
}
</script>
二、关闭窗口后传值
<body>
<input type="txt" id="txtid"/> <a href="javascript:" οnclick="SelectUser()">选择</a>
</body>
<script>
function SelectUser()
{
URL="/admin/member/select_member.aspx";
/*-----------------------判断浏览器------------*/
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
loc_y=loc_x=200;//模态窗口定位
if(is_ie)
{
loc_x=document.body.scrollLeft+event.clientX-100;
loc_y=document.body.scrollTop+event.clientY+170;
}
//弹出模态窗口
var v="";
v=window.showModalDialog(URL,self,"edge:raised;scroll:1;status:0;help:0;resizable:1;dialogWidth:"+400+"px;dialogHeight:"+350+"px;dialogTop:"+loc_y+"px;dialogLeft:"+loc_x+"px",true);
document.getElementById("txtid").value=v;
}
function clearuser()
{
document.getElementById("txtid").value="";
}
</script>
子窗口:
<table class="TableList" width="100%" align="center">
<tr class="TableData">
<td class="lefttd">
部门名称
</td>
<td style="text-align: left;" id="td1" οnclick="selectvalue()">
开发部
</td>
</tr>
</table>
<script language="javascript" type="text/javascript">
function selectvalue()
{
window.retrunValue=document.getElementById("td1").innerHTML;
}
</script>