把alert(sum)改成confirm(sum)就可以了啊

解决方案 »

  1.   

    你把页面调一下,这个还行吧,不过静态页面传递数据,这个我再查查资料<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    var test={
    "str":"0",
    "childbr":new Array(),
    "childtr":new Array(),
    "childtd":new Array(),
    "childinput1":new Array(),
    "childinp1":new Array(),
    "childinp2":new Array(),
    "childinput2":new Array(),//定义要增加文本框的数量
    "add":function(){
    this.childtr[this.str]=document.createElement("tr");
    this.childtd[this.str]=document.createElement("td");
    this.childbr[this.str]=document.createElement("br");
    this.childinp1[this.str]=document.createElement("span");
    this.childinp2[this.str]=document.createElement("span");
    this.childinput1[this.str]=document.createElement("input");
    this.childinput2[this.str]=document.createElement("input");
    document.getElementById("table1").appendChild(this.childtr[this.str]);
    this.childtr[this.str].appendChild(this.childtd[this.str]);
    this.childtd[this.str].appendChild(this.childinp1[this.str]);
    this.childinp1[this.str].innerHTML="姓名";
    this.childtd[this.str].appendChild(this.childinput1[this.str]);
    this.childtd[this.str].appendChild(this.childinp2[this.str]);
    this.childinp2[this.str].innerHTML="性别";
    this.childtd[this.str].appendChild(this.childinput2[this.str]);
    this.childtd[this.str].appendChild(this.childbr[this.str]);
    this.str=parseInt(this.str+1);
    },
    "delet":function(){
    this.str--;
    document.getElementById("table1").removeChild(this.childtr[this.str]);
    },
    "show":function(){
    var awherevalue={
    "name":new Array(),
    "sex":new Array(),
    }
    awherevalue.name[0]=this.childinput1[0].value.toString();
    awherevalue.sex[0]=this.childinput2[0].value.toString();
    var sum=this.childinp1[0].innerHTML+":"+this.childinput1[0].value.toString()+"  "+this.childinp2[0].innerHTML+":"+this.childinput2[0].value.toString()+"\n";
    for(var i=1;i<this.str;i++){
    awherevalue.name[i]=this.childinput1[i].value.toString();
    awherevalue.sex[i]=this.childinput2[i].value.toString();
    sum=sum+this.childinp1[i].innerHTML+":"+this.childinput1[i].value.toString()+"  "+this.childinp2[i].innerHTML+":"+this.childinput2[i].value.toString()+"\n";}
    confirm(sum);
    return awherevalue;}
    }function addinput(){
    test.add();
    }
    function deletinput(){
    test.delet();
    }
    function showvalue(){
    var awherevalue={
    "name":new Array(),
    "sex":new Array(),
    }
    awherevalue=test.show();
    alert(awherevalue.name[0]+" "+awherevalue.sex[0])
    window.open("target.html?awherevalue="+awherevalue)
    }
    </script>
    </head>
    <body>
    <form method="post" name="RegForm"  >
      <table id="table1"  width="570" border="0" cellspacing="10" align="left">
      </table>
      <table >
          <tr>
            <td >
                <input id="btnAdd" type="button" onclick="addinput()" value="增加节点" />
                <input id="btnRemove"  type="button"  onclick="deletinput();" value="移去节点"/>        </td>
        </tr>
        <tr>
          <td align="center">
              <input type="submit" name="Submit" onclick="showvalue()" value="提交" />
              <input type="reset" name="reset" value="重置" />      </td>
        </tr>
        </table>
    </form>
    </body>
    </html>
      

  2.   

    昨天下班了,没网上了。你把那个awherevalue声明成全局,跳转的时候不用带上,传不过去。在新页面通过opener.awherevalue访问数据,我试过了,可以。现在在网吧,没有源代码,你试试
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script type="text/javascript">
    var awherevalue={
    "name":new Array(),
    "sex":new Array(),
    }
    var test={
    "str":"0",
    "childbr":new Array(),
    "childtr":new Array(),
    "childtd":new Array(),
    "childinput1":new Array(),
    "childinp1":new Array(),
    "childinp2":new Array(),
    "childinput2":new Array(),//定义要增加文本框的数量
    "add":function(){
    this.childtr[this.str]=document.createElement("tr");
    this.childtd[this.str]=document.createElement("td");
    this.childbr[this.str]=document.createElement("br");
    this.childinp1[this.str]=document.createElement("span");
    this.childinp2[this.str]=document.createElement("span");
    this.childinput1[this.str]=document.createElement("input");
    this.childinput2[this.str]=document.createElement("input");
    document.getElementById("table1").appendChild(this.childtr[this.str]);
    this.childtr[this.str].valign="top";
    this.childtr[this.str].appendChild(this.childtd[this.str]);
    this.childtd[this.str].appendChild(this.childinp1[this.str]);
    this.childinp1[this.str].innerHTML="姓名";
    this.childtd[this.str].appendChild(this.childinput1[this.str]);
    this.childtd[this.str].appendChild(this.childinp2[this.str]);
    this.childinp2[this.str].innerHTML="性别";
    this.childtd[this.str].appendChild(this.childinput2[this.str]);
    this.childtd[this.str].appendChild(this.childbr[this.str]);
    this.str=parseInt(this.str+1);
    },
    "delet":function(){
    this.str--;
    this.childtd[this.str].removeChild(this.childinp1[this.str]);
    this.childtd[this.str].removeChild(this.childinput1[this.str]);
    this.childtd[this.str].removeChild(this.childinp2[this.str]);
    this.childtd[this.str].removeChild(this.childinput2[this.str]);
    this.childtr[this.str].removeChild(this.childtd[this.str]);
    document.getElementById("table1").removeChild(this.childtr[this.str]);
    },
    "show":function(){
    awherevalue.name[0]=this.childinput1[0].value.toString();
    awherevalue.sex[0]=this.childinput2[0].value.toString();
    var sum=this.childinp1[0].innerHTML+":"+this.childinput1[0].value.toString()+"  "+this.childinp2[0].innerHTML+":"+this.childinput2[0].value.toString()+"\n";
    for(var i=1;i<this.str;i++){
    awherevalue.name[i]=this.childinput1[i].value.toString();
    awherevalue.sex[i]=this.childinput2[i].value.toString();
    sum=sum+this.childinp1[i].innerHTML+":"+this.childinput1[i].value.toString()+"  "+this.childinp2[i].innerHTML+":"+this.childinput2[i].value.toString()+"\n";}
    return sum;
    }
    }function addinput(){
    test.add();
    }
    function deletinput(){
    test.delet();
    }
    function showvalue(){
    var sum;
    sum=test.show();
    if(confirm(sum))
    window.open(target.html);
    else{
    return false;
    }
    }</script>
    </head>
    <body><form method="post" name="RegForm"  >
      <table id="table1"  border="0" cellspacing="10" align="left" >
      </table>
      <table  style="position:absolute; bottom:92px; left: 21px;">
          <tr>
            <td >
                <input id="btnAdd" type="button" onclick="addinput()" value="增加节点" />
                <input id="btnRemove"  type="button"  onclick="deletinput();" value="移去节点"/>        </td>
        </tr>
        <tr>
          <td align="center" >
              <input  type="button" name="Submit" onclick="showvalue()" value="提交" />
              <input type="reset" name="reset" value="重置" />      </td>
        </tr>
      </table>
    </form>
    </body>
    </html>这个应该可以了,你试试.在新页面通过opener.awherevalue.name[i]和opener.awherevalue.sex[i]来访问数据.红色部分type不要用submit,要不然页面会被重新加载,然来的数据就没了.还有一个问题,就是删除后再添加,那个文本框的位置不对,这个我再研究研究
      

  4.   

    不知是否时楼主所需!
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <title>困惑好9的问题</title>
        
        <style type="text/css">
            body
            {
                font-size:12px;
            }
            
            .STYLE6 {color: #000000; font-weight: bold; }
            .STYLE7 {font-style:italic; font-weight: bold; }
        </style>
        
        <script type="text/javascript" language="javascript"> 
            //增加一个TextBox
            function Add()
            {
                var table=document.getElementById("table");
                var num=document.getElementsByName("性别").length;
                if(num>=2)
                {
                    var remove=document.getElementById("btnRemove");
                    remove.style.visibility="visible";
                }
                var tr=table.insertRow(table.rows.length-2);
                var td1=tr.insertCell();
                var td2=tr.insertCell();
                var td3=tr.insertCell();
                var td4=tr.insertCell();
                //var IDVal="性别"+(num+1);
                //alert(IDVal);
                td1.innerText="姓名"+(num+1);
                td2.innerHTML="<input type='Text' name='姓名' id='姓名"+(num+1)+"' size='18'>";
                td3.innerText="*性别"+(num+1);
                td4.innerHTML="<input type='Text' name='性别' id='性别1"+(num+1)+"' size='32'>";
                //alert(td2.innerHTML);
            }
            
            //移去最后一个TextBox
            function Remove()
            {
                var table=document.getElementById("table");
                var num=document.getElementsByName("性别").length;
                if(num<=3)
                {
                    var remove=document.getElementById("btnRemove");
                    remove.style.visibility="hidden";
                }
                table.deleteRow(table.rows.length-3);
            }
    function ck() 

         var msg="信息确认: \n \n"; 
         var itemname=document.getElementById("itemname").value; 
    if (itemname=="")
                {
                      alert("项目名称不能为空!");
                      document.getElementById("itemname").value=""; 
                    document.getElementById("itemname").focus(); 
                      return false;
                 }
    else 

    msg+="学校 : "+itemname+"\n"; 
    //获取所有input文本框
    var inputList = document.getElementsByTagName("INPUT"); for (var i = 0; i < inputList.length; i++) {
        if (inputList[i].type == "text" || inputList[i].id != "itemname") {
            if (inputList[i].name == "姓名") {
                msg += "姓名 : " + inputList[i].value; 
            }         if (inputList[i].name == "性别") {
                msg += "性别 : " + inputList[i].value + "\n"; 
            }
        }
    }
        
    if(confirm(msg)){
    return true;
    }else{
     return false; 
    }
    }

    }    </script> 
    <form method="post" name="RegForm" action="target.html" >
      <table id="table"  width="570" border="0" cellspacing="10" align="left">
        <tr>
        <p>学校 : <input type="text" name="itemname" id="itemname" value="" /> </p> 
          <td width="43">姓名1</td>
          <td width="126"><input name="姓名" type="text" id="姓名1" size="18" /></td>
          <td width="108">*性别1 </td>
          <td width="235"><input name="性别" id="性别1" type="text" size="32" /></td>
        </tr>
          <tr>
              <td>姓名2              </td>
              <td><input name="姓名" type="text" id="姓名2" size="18" /></td>
              <td>*性别2 </td>
              <td><input name="性别" id="性别2" type="text" size="32"/></td>
          </tr>
          <tr>
            <td colspan="2">
                <input id="btnAdd" type="button" onclick="Add()" value="增加节点" />
                <input id="btnRemove"  type="button" style="visibility:hidden" onclick="Remove();" value="移去节点"/>        </td>
        </tr>
        <tr>
          <td colspan="4" align="center">
              <input type="button" name="Submit" value="提交" onclick="ck()"/>
              <input type="reset" name="reset" value="重置" />      </td>
        </tr>
        </table>
    </form></html>
      

  5.   

    如果我想对"年龄"有个字数限制,比如一定要是两位数,那改怎么改限定条件?我想可能会用到数组概念吧~以下是我在function函数中添加的一段代码,但感觉判断上还是出了点问题,望指教!~
     function ck()
    {
    var 年龄1=document.all.RegForm.年龄1.value;
    var num=document.getElementsByName("年龄").length;
    //alert(num);
    var 年龄=document.getElementsByName("年龄");
                for(i=0;i<年龄.length;i++)
                {
                    if(年龄[i].value.length!=2)
                    {
                        alert("年龄"+(i+1)+"位数错误!请确保年龄为2位数字");
    document.getElementById("年龄"+(i+1)).focus();
                        return false;
                    }
                 }
    }
      

  6.   

    写js怎么写其实和语言本身关系不大,关键看你有没有写的思路,知道了自己需要什么效果,然后就去想,要达到这个效果,我需要什么,用这个语言来实现,难点在哪里,逐步的分析每一个难点,不明白的可以百度,google,这是最快速的掌握方法,等你有了一定的基础,可以买本书系统的学习,了解一些非常用的东西。总的就是你的编程的思想。
      

  7.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <title>困惑好9的问题</title>
        
        <style type="text/css">
            body
            {
                font-size:12px;
            }
            
            .STYLE6 {color: #000000; font-weight: bold; }
            .STYLE7 {font-style:italic; font-weight: bold; }
        </style>
        
        <script type="text/javascript" language="javascript"> 
            //增加一个TextBox
            function Add()
            {
                var table=document.getElementById("table");
                var num=document.getElementsByName("性别").length;
                if(num>=2)
                {
                    var remove=document.getElementById("btnRemove");
                    remove.style.visibility="visible";
                }
                var tr=table.insertRow(table.rows.length-2);
                var td1=tr.insertCell();
                var td2=tr.insertCell();
                var td3=tr.insertCell();
                var td4=tr.insertCell();
                //var IDVal="性别"+(num+1);
                //alert(IDVal);
                td1.innerText="姓名"+(num+1);
                td2.innerHTML="<input type='Text' name='姓名' id='姓名"+(num+1)+"' size='18'>";
                td3.innerText="*性别"+(num+1);
                td4.innerHTML="<input type='Text' name='性别' id='性别1"+(num+1)+"' size='32'>";
                //alert(td2.innerHTML);
            }
            
            //移去最后一个TextBox
            function Remove()
            {
                var table=document.getElementById("table");
                var num=document.getElementsByName("性别").length;
                if(num<=3)
                {
                    var remove=document.getElementById("btnRemove");
                    remove.style.visibility="hidden";
                }
                table.deleteRow(table.rows.length-3);
            }
    function ck() 

    if(ageTest())
    {
         var msg="信息确认: \n \n"; 
         var itemname=document.getElementById("itemname").value; 
            if (itemname=="")
                {
                      alert("项目名称不能为空!");
                      document.getElementById("itemname").value=""; 
                    document.getElementById("itemname").focus(); 
                      return false;
                 }
            else 
            { 
                msg+="学校 : "+itemname+"\n"; 
                //获取所有input文本框
                var inputList = document.getElementsByTagName("INPUT");            for (var i = 0; i < inputList.length; i++) {
                    if (inputList[i].type == "text" || inputList[i].id != "itemname") {
                        if (inputList[i].name == "姓名") {
                            msg += "姓名 : " + inputList[i].value; 
                        }                    if (inputList[i].name == "性别") {
                            msg += "性别 : " + inputList[i].value + "\n"; 
                        }
                    }
                }
                    
                if(confirm(msg)){
                    return true;
                }else{
                 return false; 
                }
            }
    }
            
    }function ageTest()
    {
    var ageList=document.getElementsByName("年龄");

    for(i=0;i<ageList.length;i++)
    {
    if(ageList[i].value.length >2 || isNaN(ageList[i].value))
    {
    alert("年龄"+(i+1)+"位数错误!请确保年龄为2位数字");
    ageList[i].focus();
    return false;
    }
     }  return true;
    }    </script> 
    <form method="post" name="RegForm" action="target.html" >
      <table id="table"  width="570" border="0" cellspacing="10" align="left">
        <tr>
        <p>学校 : <input type="text" name="itemname" id="itemname" value="" /> </p> 
          <td width="43">姓名1</td>
          <td width="126"><input name="姓名" type="text" id="姓名1" size="18" /></td>
          <td width="108">*性别1 </td>
          <td width="235"><input name="性别" id="性别1" type="text" size="32" /></td>
       <td width="108">*年龄1 </td>
       <td width="235"><input name="年龄" id="年龄1" type="text" size="32" /></td>
        </tr>
          <tr>
              <td>姓名2              </td>
              <td><input name="姓名" type="text" id="姓名2" size="18" /></td>
              <td>*性别2 </td>
              <td><input name="性别" id="性别2" type="text" size="32"/></td>
      <td width="108">*年龄2 </td>
       <td width="235"><input name="年龄" id="年龄2" type="text" size="32" /></td>
          </tr>
          <tr>
            <td colspan="2">
                <input id="btnAdd" type="button" onclick="Add()" value="增加节点" />
                <input id="btnRemove"  type="button" style="visibility:hidden" onclick="Remove();" value="移去节点"/>        </td>
        </tr>
        <tr>
          <td colspan="4" align="center">
              <input type="button" name="Submit" value="提交" onclick="ck()"/>
              <input type="reset" name="reset" value="重置" />      </td>
        </tr>
        </table>
    </form></html>
      

  8.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <title>困惑好9的问题</title>
        
        <style type="text/css">
            body
            {
                font-size:12px;
            }
            
            .STYLE6 {color: #000000; font-weight: bold; }
            .STYLE7 {font-style:italic; font-weight: bold; }
        </style>
        
        <script type="text/javascript" language="javascript"> 
            //增加一个TextBox
            function Add()
            {
                var table=document.getElementById("table");
                var num=document.getElementsByName("年龄").length;
                if(num>=2)
                {
                    var remove=document.getElementById("btnRemove");
                    remove.style.visibility="visible";
                }
                var tr=table.insertRow(table.rows.length-2);
                var td1=tr.insertCell();
                var td2=tr.insertCell();
                var td3=tr.insertCell();
                var td4=tr.insertCell();
                //var IDVal="性别"+(num+1);
                //alert(IDVal);
                td1.innerText="姓名"+(num+1);
                td2.innerHTML="<input type='Text' name='姓名' id='姓名"+(num+1)+"' size='18'>";
                td3.innerText="*性别"+(num+1);
                td4.innerHTML="<input type='Text' name='年龄' id='年龄"+(num+1)+"' size='32'>";
                //alert(td2.innerHTML);
            }
            
            //移去最后一个TextBox
            function Remove()
            {
                var table=document.getElementById("table");
                var num=document.getElementsByName("年龄").length;
                if(num<=3)
                {
                    var remove=document.getElementById("btnRemove");
                    remove.style.visibility="hidden";
                }
                table.deleteRow(table.rows.length-3);
            }
    function ck() 

        if(ageTest())
        {
         var msg="信息确认: \n \n"; 
         var itemname=document.getElementById("itemname").value; 
            if (itemname=="")
                {
                      alert("项目名称不能为空!");
                      document.getElementById("itemname").value=""; 
                    document.getElementById("itemname").focus(); 
                      return false;
                 }
            else 
            { 
                msg+="学校 : "+itemname+"\n"; 
                //获取所有input文本框
                var inputList = document.getElementsByTagName("INPUT");            for (var i = 0; i < inputList.length; i++) {
                    if (inputList[i].type == "text" || inputList[i].id != "itemname") {
                        if (inputList[i].name == "姓名") {
                            msg += "姓名 : " + inputList[i].value; 
                        }                    if (inputList[i].name == "年龄") {
                            msg += "年龄 : " + inputList[i].value + "\n"; 
                        }
                    }
                }
                    
                if(confirm(msg)){
                    return true;
                }else{
                 return false; 
                }
            }
        }
            
    }function ageTest()
    {
        var ageList=document.getElementsByName("年龄");
        
        for(i=0;i<ageList.length;i++)
        {
            if(ageList[i].value.length >2 || isNaN(ageList[i].value) || ageList[i].value=="")
            {
                alert("年龄"+(i+1)+"不可为空,且为2位数字");
                ageList[i].focus();
                return false;
            }
         }     return true;
    }    </script> 
    <form method="post" name="RegForm" action="target.html" >
      <table id="table"  width="570" border="0" cellspacing="10" align="left">
        <tr>
        <p>学校 : <input type="text" name="itemname" id="itemname" value="" /> </p> 
          <td width="43">姓名1</td>
          <td width="126"><input name="姓名" type="text" id="姓名1" size="18" /></td>
           <td width="108">*年龄1 </td>
           <td width="235"><input name="年龄" id="年龄1" type="text" size="32" /></td>
        </tr>
          <tr>
              <td>姓名2              </td>
              <td><input name="姓名" type="text" id="姓名2" size="18" /></td>
              <td width="108">*年龄2 </td>
           <td width="235"><input name="年龄" id="年龄2" type="text" size="32" /></td>
          </tr>
          <tr>
            <td colspan="2">
                <input id="btnAdd" type="button" onclick="Add()" value="增加节点" />
                <input id="btnRemove"  type="button" style="visibility:hidden" onclick="Remove();" value="移去节点"/>        </td>
        </tr>
        <tr>
          <td colspan="4" align="center">
              <input type="button" name="Submit" value="提交" onclick="ck()"/>
              <input type="reset" name="reset" value="重置" />      </td>
        </tr>
        </table>
    </form></html>