要求 将模态窗口中的值保存在 父页面的表格中
父页面:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<script language="javascript">
var count=0;
function tiaozhuan()
{
append_tr();
var k = window.showModalDialog("../web/tianjia.html",window,"dialogWidth:335px;status:no;dialogHeight:300px") ;
document.getElementById("txa").value=("td1"+count).value;
add();
}
function add()
{
("td1"+count).innerHTML=("td1"+count).value;
("td2"+count).innerHTML=("td2"+count).value;
("td3"+count).innerHTML=("td3"+count).value;
("td4"+count).innerHTML=("td4"+count).value;
("td5"+count).innerHTML=("td5"+count).value;
("td6"+count).innerHTML=("td6"+count).value;
("td7"+count).innerHTML=("td7"+count).value;
}
function del_tr()
{
if (count < 1) {
alert("没有内容可以删除");
return false;
}
var oldCount = count + 1;
for (var i = count; i > 0; i--) {
var deleteTr = document.getElementById("choose" + i);
if (deleteTr != null && deleteTr.checked) {
my_table.deleteRow(i); //下标从 0 开始
count--;
}
}
}
function append_tr()
{
count ++;
var tr = my_table.insertRow();
//tr.bgColor="blue";
var td0=tr.insertCell(0);
var echkbox=document.createElement("input");
echkbox.setAttribute("type","checkbox");
echkbox.setAttribute("id","choose"+count);
echkbox.setAttribute("name","cbox"+count);
echkbox.setAttribute("checked","false");
td0.appendChild(echkbox);
var td1=document.createElement("td");
td1.setAttribute("type","td");
td1.setAttribute("name","td1")
td1.setAttribute("id","td1"+count);
td1.setAttribute("value","");
tr.appendChild(td1);
var td2=document.createElement("td2");
td2.setAttribute("type","td");
td2.setAttribute("id","td2"+count);
td2.setAttribute("value","");
tr.appendChild(td2);
var td3=document.createElement("td");
td3.setAttribute("type","td");
td3.setAttribute("id","td3"+count);
td3.setAttribute("value","");
tr.appendChild(td3);
var td4=document.createElement("td");
td4.setAttribute("type","td");
td4.setAttribute("id","td4"+count);
td4.setAttribute("value","");
tr.appendChild(td4);
var td5=document.createElement("td");
td5.setAttribute("type","td");
td5.setAttribute("id","td5"+count);
td5.setAttribute("value","");
tr.appendChild(td5);
var td6=document.createElement("td");
td6.setAttribute("type","td");
td6.setAttribute("id","td6"+count);
td6.setAttribute("value","");
tr.appendChild(td6);
var td7=document.createElement("td");
td7.setAttribute("type","td");
td7.setAttribute("id","td7"+count);
td7.setAttribute("value","");
tr.appendChild(td7);
}
</script>
<body>
<form name="form1">
<div align ="right">
<input type="button" value="新增" onclick="tiaozhuan()"/>  
<input type="button" value="删除" onclick="del_tr()"/>
</div>
<table border="1" id="my_table" name="my_table" width="720" name="my_table">
<tr bgColor="green">
<td>
<input type="checkbox" id="cbox" name="cbox"/>
</td>
<input type="text" id="txa" value="">
<td id="x2" >
<font color= "red">
机组名称
</font>
</td>
<td>
<font color= "red">
KKS编码
</font>
</td>
<td>
<font color= "red">
机组类型
</font>
</td>
<td>
<font color= "red">
容量
</font>
</td>
<td>
<font color= "red">
是否国产
</font>
</td>
<td>
<font color= "red">
检修周期
</font>
</td>
<td>
<font color= "red">
投运日期
</font>
</td>
</tr>
</table>
</form>
</body>
</html>
子页面:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<script>
var k=window.dialogArguments;
//alert("ssd"+k.count);
//alert("我是从父窗口中得到的变量>>>"+k.count);
function reparent(){
var count=k.count;
k.document.getElementById("td1"+k.count).value = document.getElementById("tx1").value;
alert("td1"+k.count);
k.document.getElementById("td1"+k.count).value = document.getElementById("tx1").value ;
k.document.getElementById("td2"+k.count).value = document.getElementById("tx2").value;
k.document.getElementById("td3"+k.count).value = document.getElementById("tx3").value;
k.document.getElementById("td4"+k.count).value = document.getElementById("tx4").value;
k.document.getElementById("td5"+k.count).value = document.getElementById("tx5").value;
k.document.getElementById("td6"+k.count).value = document.getElementById("tx6").value;
k.document.getElementById("td7"+k.count).value = document.getElementById("tx7").value;
window.close();
}
</script>
<body >
<center>
<form name="form2" method="post">
<table border="1" width="310">
<tr>
<td bgColor="#cccccc" width="155">
机组名称
</td>
<td>
<input type="text" name="text1" id="tx1">
</td>
</tr>
<tr>
<td bgColor="#cccccc" width="155">
KKS编码
</td>
<td>
<input type="text" name="text2" id="tx2">
</td>
</tr>
<tr>
<td bgColor="#cccccc" width="155">
机组类型
</td>
<td>
<input type="text" name="text3" id="tx3">
</td>
</tr>
<tr>
<td bgColor="#cccccc" width="155">
容量
</td>
<td bgColor="#cccccc">
<input type="text" name="text4" id="tx4"size="10"> MW
</td>
</tr>
<tr>
<td bgColor="#cccccc" width="155">
是否国产
</td>
<td>
<input type="text" name="text5" id="tx5">
</td>
</tr>
<tr>
<td bgColor="#cccccc" width="155">
检修周期
</td>
<td bgColor="#cccccc">
<input type="text" name="text6" id="tx6" size="10"> 年
</td>
</tr>
<tr>
<td bgColor="#cccccc" width="155">
投运日期
</td>
<td>
<input type="text" name="text7" id="tx7">
</td>
</tr>
</table>
<input type="button" value="保存" onclick="reparent()">
<input type="reset" value="重置"/>
</form>
</body>
</html>