kxinzhu 2010-03-17 10:13
浏览 201
已采纳

模态页面传值 不知道哪错了 帮我看下

 

要求 将模态窗口中的值保存在 父页面的表格中

 

父页面:

<!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()"/> &nbsp;&nbsp
  <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>

 

  • 写回答

3条回答 默认 最新

  • suziwen 2010-03-17 10:44
    关注


    [code="js"]

    ("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;
    [/code]
    改为:
    [code="js"]
    document.getElementById("td1"+count).innerHTML=document.getElementById("td1"+count).value;
    document.getElementById("td2"+count).innerHTML=document.getElementById("td2"+count).value;
    document.getElementById("td3"+count).innerHTML=document.getElementById("td3"+count).value;
    document.getElementById("td4"+count).innerHTML=document.getElementById("td4"+count).value;
    document.getElementById("td5"+count).innerHTML=document.getElementById("td5"+count).value;
    document.getElementById("td6"+count).innerHTML=document.getElementById("td6"+count).value;
    document.getElementById("td7"+count).innerHTML=document.getElementById("td7"+count).value;
    [/code]

    同时你的这里也错了。

    var td2=document.createElement("td2");
    改为
    var td2=document.createElement("td");

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译