Js打开新页面,选中内容后把值返回到父页面
1. 父页面弹出子窗口
<script language="JavaScript" type="text/JavaScript">
function findcar() {
str =window.open("findcar.jsp","newwindow","height=600,width=800,toolbar=no,menubar=no,resizable=no,location=no,status=no");
if (str!=null)
str.focus(); //保持在最前面
}
</script>
2. 子页面
<script type="text/javascript">
function setFWvalue(e){
var ee = e.parentElement.parentElement.parentElement; //取得tr对象,为了取值
window.opener.document.getElementById("carTypeId").value=ee.getElementsByTagName("div")[1].innerText; //找到div里面的值,写入父页面,[1]是车型ID
window.opener.document.getElementById("carTypeName").value=ee.getElementsByTagName("div")[2].innerText; //[2]是车型
window.close();
}
</script>
<table width="100%" id="tbody" border="1">
<tr>
<th><div align="center">选择</div></th>
<th><div align="center">车型ID</div></th>
<th><div align="center">车型</div></th>
<th><div align="center">年款 </div></th>
<th><div align="center">车系</div></th>
<th><div align="center">排量 </div></th>
</tr>
<s:iterator value="car">
<tr>
<td><div align="center"><input type="radio" οnclick="setFWvalue(this)" id="prop" name="prop" value="<s:property value="typeId"></s:property>" /></div>
</td>
<td><div align="center"><s:property value="typeId" /></div></td>
<td><div align="center"><s:property value="typeCname" /></div></td>
<td><div align="center"><s:property value="typeYear" /></div></td>
<td><div align="center"><s:property value="carSeries" /></div></td>
<td><div align="center"><s:property value="enginePower" /></div></td>
</tr>
</s:iterator>
</table>
<td>加红色的<div>是为了取值,表头<th>的<div>也要写。