改为:
document.voucher.choice.value.length

解决方案 »

  1.   

    把你的这一句:
    alert(document.voucher.choice.length);
    改为:
    alert(document.voucher.choice.value.length);
      

  2.   

    <input type=button onclick="test()" value=test>
    <script>
    function test()
    {
    for(var i=0;i<document.getElementsByTagName("INPUT").length;i++)
    {
    if(document.getElementsByTagName("INPUT")[i].type=="hidden")
    alert(document.getElementsByTagName("INPUT")[0].value)
    }
    }
    </script>
      

  3.   

    <input type=button onclick="test()" value=test>
    <input type=hidden  value=test1>
    <input type=hidden  value=test2>
    <script>
    function test()
    {
    mxh=true
    for(var i=0;i<document.getElementsByTagName("INPUT").length;i++)
    {
    if(document.getElementsByTagName("INPUT")[i].type=="hidden" && mxh)
    {
    alert(document.getElementsByTagName("INPUT")[i].value)
    mxh=false
    }
    }
    }
    </script>
      

  4.   

    我意思是说hidden中存放的不是一个记录的字段值,而是一系列记录的字段值,那么得要用一个循环才能把所有的值取出来,但是值的个数我不知道,所以要用document.voucher.choice.length控制。上面贴的代码有误:             var SID="";
                 alert(document.voucher.choice.length);//说未定义
                
                  for(i=0;i&lt;document.voucher.choice.length;i++)
                 {              
                   SID=document.voucher.choice[i].value+","+SID;   
                   
                       }            
              SID=SID.substring(0,SID.length-1);谢谢!请GO UP!
      

  5.   

    <input type=hidden name=h value=aa>
    <input type=hidden name=h value=bb>
    <input type=hidden name=s value=abcdef>
    <script>
    alert(document.all.h.length) ;
    alert(document.all.h[0].value) ;
    alert(document.all.h[1].value) ;
    alert(document.all.s.value) ;
    alert(document.all.s.value.length) ;
    alert(document.all.s.length) ;
    </script>对于多个相同的元素名称可以用document.all.h.length得到元素的个数。
    只有一个元素,如果用了document.all.s.length将会出现无定义。
      

  6.   

    <input >无 id 属性时也会报这个错
    www.onlylines.com
      

  7.   

    document.voucher.choice.length这样是取得对象的长度,而对象并没有定义这个属性,所以会提示未定义document.voucher.choice.value.length
    (document.voucher.choice.value).length这样实际上是取得一个字符串对象的长度,字符串对象是有length属性的,所以这样才是正确的.
      

  8.   

    Andrawu的测试程序真好理解。谢谢各位的解答!!