function   deleteLine()   
  {   
  for   (var   i=tbody1.rows.length-1;   i>=0   ;   i--   )   
  if   (tbody1.rows[i].cells[0].firstChild.checked){
    var str = tbody1.rows[i].cells[1].firstChild.value;
    if(str.indexOf(",")!= -1){
        alert("输入中文包含,");
    }else{
        tbody1.deleteRow(i);   
    }
  }   
}

解决方案 »

  1.   

    请给出完整测试代码,在form表单里面行是动态增减, 例如3行,文本框对应的验证要求是 
    1.输入,不能含有逗号 
    2.数值 
    3.日期 谢谢
      

  2.   

    參見:
    Easy Validate简易表单验证
    http://topic.csdn.net/u/20081007/09/26060e37-865a-4247-93f3-70bf93427b70.html驗證規則可自行擴展!
      

  3.   

    怎么感觉就是用的STRING的方法啊 
      

  4.   

    <script>   
      function   deleteLine()   
      {   
      for   (var   i=tbody1.children.length-1;   i>=0   ;   i--   )   
      if   (tbody1.children[i].firstChild.firstChild.checked)   
      tbody1.deleteRow(i);   
      }   
      function   addLine()   
      {   
      elm   =   thead1.lastChild.cloneNode(true)   
      elm.style.display="block";   
      tbody1.insertBefore(elm);   
      }   
      
      
      function check(f){
        var row,cell
        for(var i=0;i<tbody1.rows.length;i++){
          row=tbody1.rows[i];
          o=row.cells[1].firstChild;
          if(!/[\u4e00-\u9fa5]/g.test(o.value)||/[,,]/g.test(o.value)){
            alert('品牌请输入中文并且不能含逗号!');
            o.focus();
            return false;
          }
          o=row.cells[2].firstChild;
          if(o.value==""||isNaN(o.value)){
            alert('数量为数量!');
            o.focus();
            return false;
          }
          o=row.cells[3].firstChild;
          if(!/^\d{4}-\d{1,2}-\d{1,2}$/.test(o.value)){
            alert('时间格式为2008-10-17,格式不正确!');
            o.focus();
            return false;
          }
        }
      }
    </script>  <form method="post" onsubmit="return check(this)">
    <TABLE cellSpacing=1 cellPadding=0 width="400" bgColor=#cccccc border=0><TBODY> 
      <thead   id=thead1>   
          <TR bgColor=#f5f5f5 height=25>
            <td height="30" colspan="4">行是动态增减, 文本框对应的要求是
            1.输入中文,不能含有逗号
            2.数值3.日期 .请高手告知js的前台验证. 万分感激:)</td>
          </tr>
          <TR bgColor=#f5f5f5 height=25>     
            <td width="38" height="30" align="center">选中</td>   
            <td width="163">品牌(中文不能有,号)</td>   
            <td width="82">数量(数值)</td>
            <td width="112">要求时间(日期)</td>
          </tr>   
          <TR bgColor=#ffffff height=25 style="display:none">     
            <td height="25"><input   type=checkbox   id=checkLine></td>   
              <td><INPUT   name=brand id="brand"   size=10 maxlength="50"></td>   
              <td><INPUT   name=amount id="amount"   size=6 maxlength="20"></td>
              <td><INPUT   name=datelimit id="datelimit" size=12 maxlength="50"></td>
          </tr>   
      </thead>   
      <tbody id=tbody1>   
         <TR bgColor=#ffffff height=25>    
            <td height="25"><input   type=checkbox   id=checkLine></td>   
              <td><INPUT   name=brand id="brand"   size=10 maxlength="50"></td>   
              <td><INPUT   name=amount id="amount"   size=6 maxlength="20"></td>
              <td><INPUT   name=datelimit id="datelimit"  size=12 maxlength="12"></td>
          </tr>
      </tbody>   
          <TR bgColor=#ffffff height=25> 
            <td height="25" colspan="4">&nbsp;&nbsp;
              &nbsp;&nbsp;&nbsp;
              <input name="button2"  type=button   onclick="addLine()"   value=添加 />
              &nbsp;&nbsp;
              <input name="button4"   type=button   onclick="deleteLine()"   value=删除 />
              &nbsp;&nbsp;
              <input name="button4"   type=submit  value=提交 /></td>
          </tr>
      </table>
      </form>
      

  5.   

     function check(){
       var o=$('checkLine');
       if(!/[\u4e00-\u9fa5]/g.test(o.value)||/[,,]/g.test(o.value)){
           alert('品牌请输入中文并且不能含逗号!');
        o.focus();
        return false;
       }
    }
    <input type="text" id="checkLine" onblur="check()"/>
      

  6.   

     if(!/[\u4e00-\u9fa5]/g.test(o.value)||/[,,]/g.test(o.value)){
    正在测试中,这句能不能改为不能为空且不能含逗号,如何更改?
      

  7.   

    if(/^\s*$|[,,]/g.test(o.value)){
    }
      

  8.   

    为空和逗号,看了showbo的代码,我捣鼓了半天,搞定了。呵呵
    最后一个问题。
    在该表单下,还有一个文本框。(不在动态行里)也需要验证下,不能为空。
    <input name="sltClient" type="text" id="sltClient" size="30" maxlength="50" >
    再次showbo感谢. 测试完成后,立马给分.
      

  9.   

    就是在一个表单里面. (再次补充说明 )
    <form ...>
    ...
    <input name="sltClient" type="text" id="sltClient" size="30" maxlength="50" > (如何验证 不能为空?)
    ...
    动态行文本框 ( 这里的验证已经ok了 )
    ....
    </form>
      

  10.   

    if(/^\s*$.test(o.value)){
    }
      

  11.   

    if(/^\s*$/g.test(o.value)){
    }我回复怎么没了呢?
      

  12.   

    function check(f){
    //使用onsubmit="return check(this)"传递进来的表单对象获取sltClient这个控件
    if(/^\s*$/.test(f.sltClient.value)){
      alert("sltClient不能为空!");f.sltClient.focus();return false;
    }
    //=============
      /*其他验证代码*/ 
      }
      

  13.   


    <script>   
      function   deleteLine()   
      {   
      for   (var   i=tbody1.children.length-1;   i>=0   ;   i--   )   
      if   (tbody1.children[i].firstChild.firstChild.checked)   
      tbody1.deleteRow(i);   
      }   
      function   addLine()   
      {   
      elm   =   thead1.lastChild.cloneNode(true)   
      elm.style.display="block";   
      tbody1.insertBefore(elm);   
      }   
      
      
      function check(f){
        var row,cell
        for(var i=0;i<tbody1.rows.length;i++){
          row=tbody1.rows[i];
          o=row.cells[1].firstChild;
          if(!/[\u4e00-\u9fa5]/g.test(o.value)||/[,,]/g.test(o.value)){
            alert('备注不能含逗号!');
            o.focus();
            return false;
          }
          o=row.cells[2].firstChild;
          if(o.value==""||isNaN(o.value)){
            alert('数量为数量!');
            o.focus();
            return false;
          }
          o=row.cells[3].firstChild;
          if(!/^\d{4}-\d{1,2}-\d{1,2}$/.test(o.value)){
            alert('时间格式为2008-10-17,格式不正确!');
            o.focus();
            return false;
          }
        }
      }
    </script>  <form method="post" onsubmit="return check(this)">
    <TABLE cellSpacing=1 cellPadding=0 width="400" bgColor=#cccccc border=0><TBODY> 
      <thead   id=thead1>   
          <TR bgColor=#f5f5f5 height=25>
            <td height="30" colspan="4"> 文本框对应的要求是
            1文本框客户也验证,不能为空. 行是动态增减,2备注可以为空,如果有内容不能含有逗号
            万分感激:)</td>
          </tr>
          <TR bgColor=#f5f5f5 height=25>
            <td height="30" colspan="4" align="center">客户&nbsp;
              <input name="sltClient" type="text" id="sltClient" size="10" maxlength="20"  ></td>
          </tr>
          <TR bgColor=#f5f5f5 height=25>     
            <td width="38" height="30" align="center">选中</td>   
            <td width="163">备注(可以为空,如果有内容不能有,号)</td>   
            <td width="82">数量(数值)</td>
            <td width="112">要求时间(日期)</td>
          </tr>   
          <TR bgColor=#ffffff height=25 style="display:none">     
            <td height="25"><input   type=checkbox   id=checkLine></td>   
              <td><INPUT   name=brand id="brand"   size=10 maxlength="50"></td>   
              <td><INPUT   name=amount id="amount"   size=6 maxlength="20"></td>
              <td><INPUT   name=datelimit id="datelimit" size=12 maxlength="50"></td>
          </tr>   
      </thead>   
      <tbody id=tbody1>   
         <TR bgColor=#ffffff height=25>    
            <td height="25"><input   type=checkbox   id=checkLine></td>   
              <td><INPUT   name=brand id="brand"   size=10 maxlength="50"></td>   
              <td><INPUT   name=amount id="amount"   size=6 maxlength="20"></td>
              <td><INPUT   name=datelimit id="datelimit"  size=12 maxlength="12"></td>
          </tr>
      </tbody>   
          <TR bgColor=#ffffff height=25> 
            <td height="25" colspan="4">&nbsp;&nbsp;
              &nbsp;&nbsp;&nbsp;
              <input name="button2"  type=button   onclick="addLine()"   value=添加 />
              &nbsp;&nbsp;
              <input name="button4"   type=button   onclick="deleteLine()"   value=删除 />
              &nbsp;&nbsp;
              <input name="button4"   type=submit  value=提交 /></td>
          </tr>
      </table>
    </form>1文本框客户也验证,不能为空. 行是动态增减,2备注可以为空,如果有内容不能含有逗号
    function check(f){
    //使用onsubmit="return check(this)"传递进来的表单对象获取sltClient这个控件
    if(/^\s*$/.test(f.sltClient.value)){
      alert("sltClient不能为空!");f.sltClient.focus();return false;
    }
    //=============
      /*其他验证代码*/ 
      }这个还是没调试出来。
      

  14.   

    ................
    <script>   
      function   deleteLine()   
      {   
      for   (var   i=tbody1.children.length-1;   i>=0   ;   i--   )   
      if   (tbody1.children[i].firstChild.firstChild.checked)   
      tbody1.deleteRow(i);   
      }   
      function   addLine()   
      {   
      elm   =   thead1.lastChild.cloneNode(true)   
      elm.style.display="block";   
      tbody1.insertBefore(elm);   
      }   
      
      
      function check(f){
    //===========================================================================
    //使用onsubmit="return check(this)"传递进来的表单对象获取sltClient这个控件
    if(/^\s*$/.test(f.sltClient.value)){
      alert("客户不能为空!");f.sltClient.focus();return false;
    }
    //===========================================================================
        var row,cell
        for(var i=0;i<tbody1.rows.length;i++){
          row=tbody1.rows[i];
          o=row.cells[1].firstChild;
          if(!/[\u4e00-\u9fa5]/g.test(o.value)||/[,,]/g.test(o.value)){
            alert('备注不能含逗号!');
            o.focus();
            return false;
          }
          o=row.cells[2].firstChild;
          if(o.value==""||isNaN(o.value)){
            alert('数量为数量!');
            o.focus();
            return false;
          }
          o=row.cells[3].firstChild;
          if(!/^\d{4}-\d{1,2}-\d{1,2}$/.test(o.value)){
            alert('时间格式为2008-10-17,格式不正确!');
            o.focus();
            return false;
          }
        }
      }
    </script>  <form method="post" onsubmit="return check(this)">
    <TABLE cellSpacing=1 cellPadding=0 width="400" bgColor=#cccccc border=0><TBODY> 
      <thead   id=thead1>   
          <TR bgColor=#f5f5f5 height=25>
            <td height="30" colspan="4"> 文本框对应的要求是
            1文本框客户也验证,不能为空. 行是动态增减,2备注可以为空,如果有内容不能含有逗号
            万分感激:)</td>
          </tr>
          <TR bgColor=#f5f5f5 height=25>
            <td height="30" colspan="4" align="center">客户&nbsp;
              <input name="sltClient" type="text" id="sltClient" size="10" maxlength="20"  ></td>
          </tr>
          <TR bgColor=#f5f5f5 height=25>     
            <td width="38" height="30" align="center">选中</td>   
            <td width="163">备注(可以为空,如果有内容不能有,号)</td>   
            <td width="82">数量(数值)</td>
            <td width="112">要求时间(日期)</td>
          </tr>   
          <TR bgColor=#ffffff height=25 style="display:none">     
            <td height="25"><input   type=checkbox   id=checkLine></td>   
              <td><INPUT   name=brand id="brand"   size=10 maxlength="50"></td>   
              <td><INPUT   name=amount id="amount"   size=6 maxlength="20"></td>
              <td><INPUT   name=datelimit id="datelimit" size=12 maxlength="50"></td>
          </tr>   
      </thead>   
      <tbody id=tbody1>   
         <TR bgColor=#ffffff height=25>    
            <td height="25"><input   type=checkbox   id=checkLine></td>   
              <td><INPUT   name=brand id="brand"   size=10 maxlength="50"></td>   
              <td><INPUT   name=amount id="amount"   size=6 maxlength="20"></td>
              <td><INPUT   name=datelimit id="datelimit"  size=12 maxlength="12"></td>
          </tr>
      </tbody>   
          <TR bgColor=#ffffff height=25> 
            <td height="25" colspan="4">&nbsp;&nbsp;
              &nbsp;&nbsp;&nbsp;
              <input name="button2"  type=button   onclick="addLine()"   value=添加 />
              &nbsp;&nbsp;
              <input name="button4"   type=button   onclick="deleteLine()"   value=删除 />
              &nbsp;&nbsp;
              <input name="button4"   type=submit  value=提交 /></td>
          </tr>
      </table>
    </form>
      

  15.   

    又改了要求了。function check(f){
       
        if(/^\s*$/.test(f.sltClient.value)){
          alert("客户不能为空!");f.sltClient.focus();return false;
        }    var row,cell
        for(var i=0;i<tbody1.rows.length;i++){
          row=tbody1.rows[i];
          o=row.cells[1].firstChild;      if(o.value!=""&&/[,,]/g.test(o.value)){//=========================
            alert('备注不能含逗号!');
            o.focus();
            return false;
          }
          o=row.cells[2].firstChild;
          if(o.value==""||isNaN(o.value)){
            alert('数量为数量!');
            o.focus();
            return false;
          }
          o=row.cells[3].firstChild;
          if(!/^\d{4}-\d{1,2}-\d{1,2}$/.test(o.value)){
            alert('时间格式为2008-10-17,格式不正确!');
            o.focus();
            return false;
          }
        }
      }
      

  16.   

    OK了,不过还有个小问题      if(!/[\u4e00-\u9fa5]/g.test(o.value)||/[,,]/g.test(o.value)){
            alert('备注不能含逗号!');
    备注可以空,但不能含逗号怎么改?
      

  17.   

    改成这样貌似可以不知道对不对
    if(!o.value==""&&/[,,]/g.test(o.value)){
      

  18.   

    showbo兄真是一位耐心的老师,顶!
      

  19.   

    我是要可以为空呀
    我自己改了下你看行吗if(!o.value==""&&/[,,]/g.test(o.value)){