现有table例如:<form id="formId" method="post">
<input type="text" name="card.id"  class="required"/>
<input type="text" name="card.type"  class="required"/>
<input type="button" name="addOneRow"/><table id="tid">
<thead>
<tr><td>ID</td><td>NAME</td><td>CODE</td></tr>
</thead>
<tbody></tbody>
<tfoot>
<tr style="disply:none">
<td><input name="person.id" type="text" class="required"></td>
<td><input name="person.name" type="text" class="required"></td>
<td><input name="person.code" type="text" class="required number"></td>
</tfoot>
</table>
</from>
tfoot相当于源,clone一份到tbody填写数据,
当form提交时通过remove掉tfoot中tr,(没有removeclass是因为考虑到tfoot中的input较多情况),但是card.id,card.name没有填写提交表单时同样remove掉了tfoot中tr(这是不希望的情况),问有没有from表单提交时放过某些添加了class的字段验证?例如:不验证tfoot中的person.id、person.name、person.code

解决方案 »

  1.   

    通过按钮addOneRow动态增加行(通过clone tfoot 的tr到tbody),form 提交时remove掉tfoot的tr,但是form表单提交的不只是person对象,还有card对象,当form提交时card对象的某个属性验证不通过时,
    在点击提交按钮的function中是先remove tfoot 再 submit form,也就是不论表单有没有验证通过,tfoot中的tr都romve掉了,现想:不remove tfoot中的tr,而是在submit时不验证这个tr(不去掉tr的class,这样就避免在clone他时再一一添加class)
      

  2.   

    也不想把此tr内容提出到form外,这样感觉就拆散了table的整体性。
      

  3.   

    var trHtml = '<td><input name="person.id" type="text" class="required"></td>
    <td><input name="person.name" type="text" class="required"></td>
    <td><input name="person.code" type="text" class="required number"></td>
    ';function addRow(){
    var tableBody = document.getElementById('myTableBody');
    var newRow = document.createElement('tr');
    newRow.innerHTML=trHtml ;
    tableBody.appendChild(newRow); 
    }
      

  4.   

    存在问题代码:
    //移掉必填项验证 
    function removeRequired(){
       $("tfoot tr").each(function(i){
    $(this).empty();
       });
    }
    //新增页面保存
    $("#save").click(function(){
        $("input[name=densityRep.month]").parent().find("div").remove();
    $.ajax({
       type: "POST",dataType:"json",
       url: "../dustAjax/checkDensityRepMonth.action",
       data: "para1="+$("input[name=densityRep.month]").val(),
       success: function(req){
    if(req.result=="ok"){
       $("#addForm").attr("action","../densityRep/save.action");
       removeRequired();
       $("#addForm").submit();
    }else{
       $("input[name=densityRep.month]").parent()
                          .append("<div>"+月份不允许重复!</div>");
    }
       }
    }); 
        });