下面应该如何改才能获取所有ss的名称
<!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=utf-8" />
<title>无标题文档</title>
</head><body>
<form  >
<script language="javascript" type="text/javascript">
function jian()
{
  // var aa = new Array(document.getElementsByName("ss"));
   //var arrbb=new Array(document.GetElementsByName("ss"));
   var hh=document.getElementsByName("ss").value;
   alert(hh);
   var arrbb=document.getElementByTagNames("hidden");
   
   var cc;
   for(var i=0; i<arrbb.length;i++)
   {
   //cc=cc+arrbb[i].etAttribute("name");
    var oSel = arrbb[i].value;   cc=cc+ oSel;
   cc=cc+",";
   }
   
   
   alert(cc);}</script>
<input type="hidden" value="" name="ss" value="1" />
<input type="hidden" value="" name="ss" value="2" />
<input type="hidden" value="" name="ss" value="3" />
<input type="hidden" value="" name="ss" value="4" />
<input type="hidden" value="" name="ss" value="5" />
<input type="hidden" value="" name="ss" value="6" />
<input type="hidden" value="" name="ss" value="7" />
<input type="hidden" value="" name="ss" value="8" />
<input type="hidden" value="" name="ss" value="9" />
<input name="dd" type="button"  onclick="jian()"/></form>
</body>
</html>

解决方案 »

  1.   

    var a = document.getElementsByName("ss")返回的是一个数组
    需要type=hidden的可以用 a[i].type == "hidden"来判断
      

  2.   

    <!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=utf-8" />
    <title>无h・文档</title>
    </head><body>
    <form >
    <script language="javascript" type="text/javascript">
    function jian()
    {
      // var aa = new Array(document.getElementsByName("ss"));
      //var arrbb=new Array(document.GetElementsByName("ss"));
      //var hh=document.getElementsByName("ss").value;
      //alert(hh);
      var arrbb=document.getElementsByTagName("input");
        
      var cc="";
      for(var i=0; i<arrbb.length;i++)
      {
      //cc=cc+arrbb[i].etAttribute("name");
      if(arrbb[i].type=="hidden"){
        var oSel = arrbb[i].value;    cc=cc+ oSel;
        cc=cc+",";
      }
      }
        
        
      alert(cc);}</script>
    <input type="hidden" name="ss" value="1" />
    <input type="hidden" name="ss" value="2" />
    <input type="hidden" name="ss" value="3" />
    <input type="hidden" name="ss" value="4" />
    <input type="hidden" name="ss" value="5" />
    <input type="hidden" name="ss" value="6" />
    <input type="hidden" name="ss" value="7" />
    <input type="hidden" name="ss" value="8" />
    <input type="hidden" name="ss" value="9" />
    <input name="dd" type="button" onclick="jian()"/></form>
    </body>
    </html>
      

  3.   

    只要一个type 就可以判断了!
      

  4.   

    不光是数组问题
    LZ的input里有俩value,只会取第一个的值,所以取出来都是""
    改好的代码如下<!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=utf-8" />
    <title>无标题文档</title>
    </head><body>
    <form >
    <script language="javascript" type="text/javascript">
    function jian()
    {
      // var aa = new Array(document.getElementsByName("ss"));
      //var arrbb=new Array(document.GetElementsByName("ss"));
      var hh=document.getElementsByName("ss");
      alert(hh.length);
     // var arrbb=document.getElementByTagNames("hidden");
        
      var cc="";
      for(var i=0; i<hh.length;i++)
      {
      //cc=cc+arrbb[i].etAttribute("name");
      var oSel = hh[i].value;
      cc=cc+ oSel;
      cc=cc+",";
      }
        
      alert(cc);}</script>
    <input type="hidden" name="ss" value="" value="1" /> <!-- 如果有俩 value 则只取第一个的值  -->
    <input type="hidden" name="ss" value="2" />  
    <input type="hidden" name="ss" value="3" />  
    <input type="hidden" name="ss" value="4" />  
    <input type="hidden" name="ss" value="5" />  
    <input type="hidden" name="ss" value="6" />  
    <input type="hidden" name="ss" value="7" />  
    <input type="hidden" name="ss" value="8" />  
    <input type="hidden" name="ss" value="9" />  
    <input name="dd" type="button" onclick="jian()"/></form>
    </body>
    </html>
      

  5.   


    <html>
    <head>
    <script language="javascript" type="text/javascript">
    function jian()
    {
    var inputTag = document.getElementsByTagName("input");
    var yourWant = "";
    for(var i=0;i<inputTag.length;i++){
    if(inputTag[i].type=="hidden"){
    var ss = inputTag[i].value; yourWant += ","+ss;
    }
    }
    yourWant = yourWant.substring(1);
    alert(yourWant);
    }</script>
    </head>
    <body>
    <form ><input type="hidden"  name="ss" value="1" />
    <input type="hidden"  name="ss" value="2" />
    <input type="hidden"  name="ss" value="3" />
    <input type="hidden"  name="ss" value="4" />
    <input type="hidden"  name="ss" value="5" />
    <input type="hidden"  name="ss" value="6" />
    <input type="hidden"  name="ss" value="7" />
    <input type="hidden"  name="ss" value="8" />
    <input type="hidden"  name="ss" value="9" />
    <input name="dd" type="button" onclick="jian()" value="aaaaaaa"/></form>
    </body>
    </html>
      

  6.   


    <script language="javascript" type="text/javascript">
    function jian()
    {
      // var aa = new Array(document.getElementsByName("ss"));
      //var arrbb=new Array(document.GetElementsByName("ss"));
      //var hh=document.getElementsByName("ss").value;
      //alert(hh);
      var arrbb=document.getElementsByTagName("input");
        
      var cc="";
      for(var i=0; i<arrbb.length;i++)
      {
      //cc=cc+arrbb[i].etAttribute("name");
      if(arrbb[i].type == "hidden"){
      var oSel = arrbb[i].value;  cc=cc+ oSel;
      cc=cc+",";
      }
      }
      alert(cc);}
    </script>
    </head><body>
    <form>
    <input type="hidden" value="" name="ss" value="1" />
    <input type="hidden" value="" name="ss" value="2" />
    <input type="hidden" value="" name="ss" value="3" />
    <input type="hidden" value="" name="ss" value="4" />
    <input type="hidden" value="" name="ss" value="5" />
    <input type="hidden" value="" name="ss" value="6" />
    <input type="hidden" value="" name="ss" value="7" />
    <input type="hidden" value="" name="ss" value="8" />
    <input type="hidden" value="" name="ss" value="9" />
    <input name="dd" type="button" onclick="jian()" value="点击"/></form>