有大侠知道 怎么限制 最多可以添加20个文本框吗?
    知道的麻烦帮帮忙
  JS+html<script   language="javascript">                                  
  function   add()                                  
  {  
        option   =   new   Array();  
        proportion   =   new   Array();                          
        str='<table>';  
        str=str+'<tr   align=center   valign=middle   bgcolor=#FFFFFF>';  
        str=str+'<td   width="100%"   height="25"><input   type="text"   name=proportion></td>';  
        str=str+'<td   width="100%"   height="25"><input   type="button"   name=del   onclick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex)"   value="删除"></td>';  
        str=str+'</tr></table>';  
        window.upid.innerHTML+=str+'';  
  }                                  
  </script>  
  <html>  
  <head>  
  <title>Untitled   Document</title>  
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">  
  </head>    
  <body>      
  <form   name="myform"   onsubmit="javascript:return   check()">      
        <table>      
                <tr>          
                        <td>    
                                <input   name="Submit2"   type="button"   onclick="javascript:add()"   value="增加">      
                        </td>          
                </tr>          
                <tr>              
                        <td>          
                        <div   id="upid"></div>      
                        </td>          
                </tr>    
        </table>                                  
  </form>                                  
  </body>                                  
  </html>   

解决方案 »

  1.   


    function add()
    {
    var tables=window.upid.innerHTML.getElementsByTagName("TABLE")
    if(tables.length>19)
    return;
    }
      

  2.   

    <input  type="text"  name="proportion" size="20" > 
      

  3.   


    function  add()                                  
      {  
         if(getLength()==20)
            return;
         //继续操作}function getLength(){
       var texts=document.getElementsByTagName("input");
       var inputlength=0;
       for( var i=0;i<texts.length;i++){
           if(texts[i].type="text")
                inputlength++;
      }
      return inputlength;
    }
      

  4.   

    找个变量记录下来
    <script  language="javascript">    
    var i=0;                              
      function  add()                                  
      if(i>=19){return false;}
      {  
            option  =  new  Array();  
            proportion  =  new  Array();                          
            str=' <table>';  
            str=str+' <tr  align=center  valign=middle  bgcolor=#FFFFFF>';  
            str=str+' <td  width="100%"  height="25"> <input  type="text"  name=proportion> </td>';  
            str=str+' <td  width="100%"  height="25"> <input  type="button"  name=del  onclick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex)"  value="删除"> </td>';  
            str=str+' </tr> </table>';  
    i++;
            window.upid.innerHTML+=str+'';  
      }                                  
      </script>  
      

  5.   

    刚才没看清楼主的问题,误以为是设置text的size 
     <td>          
                            <div  id="upid"> </div>      
                            </td>window.upid是取上面id为upid的div块吗?,学习了!
      

  6.   

    <script  language="javascript">   
      var count=0;                               
      function  add()                                  
      {  
    if(count<20)
            {
    option  =  new  Array();  
            proportion  =  new  Array();                          
            str=' <table>';  
            str=str+' <tr  align=center  valign=middle  bgcolor=#FFFFFF>';  
            str=str+' <td  width="100%"  height="25"> <input  type="text"  name=proportion value=这是第:'+(count+1)+'个> </td>';  
            str=str+' <td  width="100%"  height="25"> <input  type="button"  name=del  onclick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex);count--"  value="删除"> </td>';  
            str=str+' </tr> </table>';  
            window.upid.innerHTML+=str+'';  
    count++;
    }
      }                                  
      </script>  
      <html>  
      <head>  
      <title>Untitled  Document </title>  
      <meta  http-equiv="Content-Type"  content="text/html;  charset=gb2312">  
      </head>    
      <body>      
      <form  name="myform"  onsubmit="javascript:return  check()">      
            <table>      
                    <tr>          
                            <td>    
                                    <input  name="Submit2"  type="button"  onclick="javascript:add()"  value="增加">      
                            </td>          
                    </tr>          
                    <tr>              
                            <td>          
                            <div  id="upid"> </div>      
                            </td>          
                    </tr>    
            </table>                                  
      </form>                                  
      </body>                                  
      </html>  
      

  7.   

    1  定义一个全局记录变量,在 add函数里累加 就可以,并且判断这个变量如果加够数量就return false;
    2  给table定义一个id,通过getElementById的方式获得table对象,判断该对象中的文本框个数
    循环出表格中所有的TagName 判断类型是否是text 并且数量是否是20个,如果是 return false;大概思路这样