一个展现页面有十个文本框
而且名称一样例如<input   type=text   name=text>
这十个文本框,现在都有值(从后天差出来的)。
问题是如果客户只改变了其中的一个值或多个值,怎么知道具体改的是哪一个?改了几个 

解决方案 »

  1.   

    可以在input里做个标记位(做个属性),如果修改,属性也跟着修改。
    相同名子就是控件数组,不会报错!
      

  2.   

    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="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
     </head> <body>

    <input  type=text  name=text value="a" /> 
    <input  type=text  name=text value="b" /> 
    <input  type=text  name=text value="c" /> 
    <input  type=text  name=text value="d" /> 
    <input  type=text  name=text value="e" /> 
    修改一两个以后,点击<input type="button" value="检查" id="btnCheck" /><script type="text/javascript">
    <!--
    document.getElementById("btnCheck").onclick = function() {
    var tbxs = document.getElementsByTagName("input");
    var tbx;
    for (var i=0; i<tbxs.length; i++)
    {
    tbx = tbxs[i];
    if (tbx.value != tbx.defaultValue)
    {
    alert("No. " + (i+1) + " textbox has changed from " + tbx.defaultValue + " to " + tbx.value);
    }
    }
    };
    //-->
    </script>
     </body>
    </html>
      

  3.   


    <html>
        <head>
            <script>
                var oldValue=[];
                var newValue=[];
                window.onload=function(){
                    var oldValue= document.getElementsByName("1");
                }
                function test(){
                    var index=0;
                    var newValue= document.getElementsByName("1");
                    for(var i=0;i<newValue.length;i++){
                        if(newValue[i].value!=oldValue[i].value){
                             index++
                        }
                    }
                    alert("改变了"+index+"个值")
                }
            </script>
        </head>    <body>
            <input type="text" name="1">
            <input type="text" name="1">
            <input type="text" name="1">
            <input type="button" value="测试" onclick="test()">
        </body>
    </html>
      

  4.   


    <body>
    <input type=text id=t1 name=text onpropertychange="recordDirty(this);" oninput="recordDirty(this);" value=123 /><br>
    <input type=text id=t2 name=text onpropertychange="recordDirty(this);" oninput="recordDirty(this);" value=456 /><br> 
    <input type=text id=t3 name=text onpropertychange="recordDirty(this);" oninput="recordDirty(this);" /><br>
    <input type=text id=t4 name=text onpropertychange="recordDirty(this);" oninput="recordDirty(this);" /><br>
    <input type=text id=t5 name=text onpropertychange="recordDirty(this);" oninput="recordDirty(this);" /><br>
    <input type=text id=t6 name=text onpropertychange="recordDirty(this);" oninput="recordDirty(this);" /><br>
    <input type=text id=t7 name=text onpropertychange="recordDirty(this);" oninput="recordDirty(this);" /> 
    <body>
    <script>
    var arrOld=[], sChangedID='';
    window.onload=function(){
      var o=document.getElementsByName("text");
      for(var i=0;i<o.length;i++){  arrOld.push(o[i].value); }
    }function recordDirty(o){
      var n=o.id.replace("t","")*1-1;
      if(o.value!=arrOld[n]&&sChangedID.indexOf(o.id+",")==-1){ sChangedID+=o.id+"," }
      else if(o.value==arrOld[n]&&sChangedID.indexOf(o.id+",")!=-1){ sChangedID=sChangedID.replace(o.id+",","")}
      
      var n=sChangedID.split(",").length-1;
      if(n==0){alert('一个没改~~');  return}
      alert('文本框改动了 '+n+" 个,它们是:"+sChangedID)
    }
    </script>
      

  5.   

    这样简单点
    <body>
    <input type=text name=text onchange="tip(event);" value=123 /><br>
    <input type=text name=text onchange="tip(event);" value=456 /><br> 
    <input type=text name=text onchange="tip(event);" /><br>
    <body>
    <script>
    function tip(evt)
    {
      alert(evt.srcElement.vaule);
    }</script>