Js打開新頁面,選中内容後把值傳回到父頁面
轉發 評論 2011-11-25 09:12
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>也要寫。