你指的顺序是 按input出现的次序还是 id的顺序如果是出现次序就简单点var inputCollection = new Array();
var inputs = [form].getElementsByTagName("input");
for(var i=0;i<inputs.length;i++)
{
if((s=inputs[i]).type=="text" && s.name.replace("a","b")==s.id)
inputCollection.push(s);
}

解决方案 »

  1.   

    var a=document.getElementsByTagName("input")
    for(var i=0;i<a.length;i++){
       if(a[i].type=="text"){
          if(a[i].name.substr(0,1)=="a"){
             alert(a[i].value)
          }
       }
    }
      

  2.   

    Quickly L@_@K<!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>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="[email protected]" />
      <meta name="keywords" content="javascript" />
      <meta name="description" content="for javascript region of csdn" />
     </head> <body>
    <input type="text" name="a1" id="b1">
    <input type="text" name="a2" id="b2">
    <input type="text" name="a3" id="b3">
    <input type="text" name="a4" id="b4">
    <input type="button" id="btnShow" value="Show" onclick="showTextBoxes();" />
      <script type="text/javascript">
      <!--
    function showTextBoxes()
    {
        var colInput = document.getElementsByTagName("input");
        
        for (var i=0; i<colInput.length; i++)
        {
            if (colInput[i].type=="text")
            {
                if (colInput[i].value=="")
                {
                    alert(colInput[i].id + " is empty.")
                }
                else
                {
                    alert(colInput[i].id + " is not empty.\nThe value is " + colInput[i].value)
                }
            }
        }
    }
      //-->
      </script>
     </body>
    </html>
      

  3.   

    如果是按name排列..var inputCollection = new Array();
    var arr = new Array();
    var inputs = [form].getElementsByTagName("input");
    for(var i=0;i<inputs.length;i++)
    if((s=inputs[i]).type=="text" && s.name.replace("a","b")==s.id)
    arr[arr.length]=Number(s.name.replace("a"));arr.sort();
    for(var i=0;i<arr.length;i++)
    inputCollection.push(document.getElementById("a" + arr[i]));
    inputCollection就是集合
      

  4.   

    [form] 是 表单元素<form name="xxx">........</form>的name
    如果不知道可以用 document代替
      

  5.   

    修正一下,L@_@K<!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>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="[email protected]" />
      <meta name="keywords" content="javascript" />
      <meta name="description" content="for javascript region of csdn" />
     </head> <body>
    <input type="text" name="a1" id="b1">
    <input type="text" name="a2" id="b2">
    <input type="text" name="a3" id="b3">
    <input type="text" name="a4" id="b4">
    <input type="button" id="btnShow" value="Show" onclick="showTextBoxes();" />
      <script type="text/javascript">
      <!--
    function showTextBoxes()
    {
        var colInput = document.getElementsByTagName("input");
        var textCollection = new Array();
        for (var i=0; i<colInput.length; i++)
        {
            if (colInput[i].type=="text")
            {
                if (colInput[i].value=="")
                {
                    alert(colInput[i].id + " is empty.")
                }
                else
                {
                    textCollection[textCollection.length] = colInput[i].id + " | " + colInput[i].value;
                }
            }
        }
        alert(textCollection);
    }
      //-->
      </script>
     </body>
    </html>
      

  6.   

    lz 别客气,赶紧 sf 吧,哈
      

  7.   

    对了。。还要问下。。怎么用个input框把textCollection给显示出来
      

  8.   

    怎么用个input框把textCollection给显示出来?L@_@K<!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>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="[email protected]" />
      <meta name="keywords" content="javascript" />
      <meta name="description" content="for javascript region of csdn" />
     </head> <body>
    <input type="text" name="a1" id="b1">
    <input type="text" name="a2" id="b2">
    <input type="text" name="a3" id="b3">
    <input type="text" name="a4" id="b4">
    <input type="button" id="btnShow" value="Show" onclick="showTextBoxes();" />  <script type="text/javascript">
      <!--
    function showTextBoxes()
    {
        var colInput = document.getElementsByTagName("input");
        var textCollection = new Array();
        for (var i=0; i<colInput.length; i++)
        {
            if (colInput[i].type=="text")
            {
                if (colInput[i].value=="")
                {
                    alert(colInput[i].id + " is empty.")
                }
                else
                {
                    textCollection[textCollection.length] = colInput[i].id + " | " + colInput[i].value;
                }
            }
        }
        if (textCollection.length > 0)
        {
            alert(textCollection);        var oNewInput = document.createElement("input");
            oNewInput.type = "text";
            oNewInput.value = textCollection;
            document.body.appendChild(oNewInput);
        }
    }
      //-->
      </script>
     </body>
    </html>
      

  9.   

    var textCollection = new Array();
    var inputs = document.getElementsByTagName("input");
    for(var i=0;i<inputs.length;i++)
    {
    if((s=inputs[i]).type=="text")
    {
    if(v=s.value.replace(/(^\s+)|(\s+$)/g,"").length>0)
    textCollection.push(s.value);
    else
    alert(s.id + ": 为空");
    }
    }
    alert(textCollection);
      

  10.   

    To bcc1o()JS 好好玩滴,哈
      

  11.   

    yixianggao(你我他,三人行必有我师焉!) 
    这样动态生成那判定就没有意义了-。-
    我设想的是得到最终的textCollection,就是数据填完的textCollection-.-,这样填一个数据点show也会出textCollection。。-。-再帮帮忙,改下下吧^^
      

  12.   

    看看行不,俺先去吃饭了,哈<!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>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="[email protected]" />
      <meta name="keywords" content="javascript" />
      <meta name="description" content="for javascript region of csdn" />
     </head> <body>
    <div id="divContainer">
        <input type="text" name="a1" id="b1">
        <input type="text" name="a2" id="b2">
        <input type="text" name="a3" id="b3">
        <input type="text" name="a4" id="b4">
    </div>
    <input type="button" id="btnShow" value="Show" onclick="showTextBoxes();" /><br />
    <input type="text" id="tbxResult">  <script type="text/javascript">
      <!--
    function showTextBoxes()
    {
        var colInput = document.getElementById("divContainer").getElementsByTagName("input");
        var textCollection = new Array();
        for (var i=0; i<colInput.length; i++)
        {
            if (colInput[i].type=="text")
            {
                if (colInput[i].value=="")
                {
                    alert(colInput[i].id + " is empty.")
                }
                else
                {
                    textCollection[textCollection.length] = colInput[i].id + " | " + colInput[i].value;
                }
            }
        }
        if (textCollection.length > 0)
        {
            alert(textCollection);
            document.getElementById("tbxResult").value = textCollection;
        }
    }
      //-->
      </script>
     </body>
    </html>
      

  13.   

    恩,差不多就是这个效果啦。。谢谢谢谢。。非常感谢。。lol,SF拉~<!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>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="[email protected]" />
      <meta name="keywords" content="javascript" />
      <meta name="description" content="for javascript region of csdn" />
     </head> <body>
    <div id="divContainer">
        <input type="text" name="a1" id="b1">
        <input type="text" name="a2" id="b2">
        <input type="text" name="a3" id="b3">
        <input type="text" name="a4" id="b4">
    </div>
    <input type="button" id="btnShow" value="Show" onclick="return showTextBoxes();" /><br />
    <input type="text" id="tbxResult">  <script type="text/javascript">
      <!--
    function showTextBoxes()
    {
        var colInput = document.getElementById("divContainer").getElementsByTagName("input");
        var textCollection = new Array();
        for (var i=0; i<colInput.length; i++)
        {
            if (colInput[i].type=="text")
            {
                if (colInput[i].value=="")
                {
                    alert(colInput[i].id + " is empty.")
                    return false;
                }
                else
                {
                    textCollection[textCollection.length] = colInput[i].id + " | " + colInput[i].value;
                }
            }
        }
        if (textCollection.length > 0)
        {
            alert(textCollection);
            document.getElementById("tbxResult").value = textCollection;
        }
    }
      //-->
      </script>
     </body>
    </html>