Javascript 将表中的所有字段留空

Javascript 将表中的所有字段留空,javascript,jquery,Javascript,Jquery,我有一个很大的表单,估计有170个输入字段,由html表划分为子部分。 下面是我的一个子部分:- <table width="90%" border=0 align="center" cellpadding="0" cellspacing="1" > <tr align="center"> <th height="20" colspan="4"> Upgradings / Repair Work <?php

我有一个很大的表单,估计有170个输入字段,由html表划分为子部分。 下面是我的一个子部分:-

  <table width="90%"  border=0 align="center" cellpadding="0" cellspacing="1" >
    <tr align="center"> 
      <th height="20" colspan="4"> Upgradings / Repair Work 
        <?php if($ResultRow->shipnam != '') echo(" for ".$ResultRow->shipnam);?>
      </th>
    </tr>

    <tr> 
      <td width="15%" height="20" align="right">Date est. start Upgrade : </td>
      <td height="20" width="30%">
        <input name="est_start_upgrade" type="text" id="est_start_upgrade" size="10" maxlength="11" tabindex="1" onBlur="cal_prs_date1(this)" value="<?php echo(trim($_POST['est_start_upgrade']));?>" />
        <a href="javascript:est_start_upgrade.popup();" tabindex="1" ><img src="../../common/date_component/img/cal.gif" width="16" height="16" border="0" alt="Click here to pick up the date"></a>&nbsp; 
      </td>
            <td width="15%" height="20" align="right"> Date est. end Upgrade : </td>
      <td height="20" width="30%">
        <input name="est_end_upgrade" type="text" id="est_end_upgrade" size="10" maxlength="11" tabindex="1" onBlur="cal_prs_date1(this)" value="<?php echo(trim($_POST['est_end_upgrade']));?>" /> 
        <a href="javascript:est_end_upgrade.popup();" tabindex="1" ><img src="../../common/date_component/img/cal.gif" width="16" height="16" border="0" alt="Click here to pick up the date"></a>&nbsp; 
      </td>
    </tr>

    <tr> 
      <td  height="20" align="right">Date actual start Upgrade : </td>
      <td height="20" >
        <input name="act_start_upgrade" type="text" id="act_start_upgrade" size="10" maxlength="11" tabindex="1" onBlur="cal_prs_date1(this)" value="<?php echo(trim($_POST['act_start_upgrade']));?>" />
        <a href="javascript:act_start_upgrade.popup();" tabindex="1" ><img src="../../common/date_component/img/cal.gif" width="16" height="16" border="0" alt="Click here to pick up the date"></a>&nbsp; 
      </td>
            <td height="20" align="right"> Date actual complete Upgrade : </td>
      <td height="20" >
        <input name="act_end_upgrade" type="text" id="act_end_upgrade" size="10" maxlength="11" tabindex="1" onBlur="cal_prs_date1(this)" value="<?php echo(trim($_POST['act_end_upgrade']));?>" /> 
        <a href="javascript:act_end_upgrade.popup();" tabindex="1" ><img src="../../common/date_component/img/cal.gif" width="16" height="16" border="0" alt="Click here to pick up the date"></a>&nbsp; 
      </td>
    </tr>       


    <tr> 
      <td height="20" align="right">Date est. start Repair : </td>
      <td height="20" >
        <input name="est_start_repair" type="text" id="est_start_repair" size="10" maxlength="11" tabindex="1" onBlur="cal_prs_date1(this)" value="<?php echo(trim($_POST['est_start_repair']));?>" />
        <a href="javascript:est_start_repair.popup();" tabindex="1" ><img src="../../common/date_component/img/cal.gif" width="16" height="16" border="0" alt="Click here to pick up the date"></a>&nbsp; 
      </td>
          <td height="20" align="right"> Date est. end Repair : </td>
      <td height="20" >
        <input name="est_end_repair" type="text" id="est_end_repair" size="10" maxlength="11" tabindex="1" onBlur="cal_prs_date1(this)" value="<?php echo(trim($_POST['est_end_repair']));?>" /> 
        <a href="javascript:est_end_repair.popup();" tabindex="1" ><img src="../../common/date_component/img/cal.gif" width="16" height="16" border="0" alt="Click here to pick up the date"></a>&nbsp; 
      </td>
    </tr>

    <tr> 
      <td height="20" align="right">Date actual start Repair : </td>
      <td height="20" >
        <input name="act_start_repair" type="text" id="act_start_repair" size="10" maxlength="11" tabindex="1" onBlur="cal_prs_date1(this)" value="<?php echo(trim($_POST['act_start_repair']));?>" />
        <a href="javascript:act_start_repair.popup();" tabindex="1" ><img src="../../common/date_component/img/cal.gif" width="16" height="16" border="0" alt="Click here to pick up the date"></a>&nbsp; 
      </td>
          <td height="20" align="right"> Date actual complete Repair : </td>
      <td height="20" >
        <input name="act_end_repair" type="text" id="act_end_repair" size="10" maxlength="11" tabindex="1" onBlur="cal_prs_date1(this)" value="<?php echo(trim($_POST['act_end_repair']));?>" /> 
        <a href="javascript:act_end_repair.popup();" tabindex="1" ><img src="../../common/date_component/img/cal.gif" width="16" height="16" border="0" alt="Click here to pick up the date"></a>&nbsp; 
      </td>
    </tr>    

    <tr> 
      <td height="20" align="right">Upgrading info : </td>
      <td height="20" >
        <input name="upgrading_info" type="text" id="upgrading_info" value="<?php echo(trim($_POST['upgrading_info']));?>" /> &nbsp; 
      </td>
          <td height="20" align="right">Repair info :</td>
      <td height="20" >
        <input name="repair_info" type="text" id="repair_info"   value="<?php echo(trim($_POST['repair_info']));?>" /> &nbsp; 
      </td>
    </tr>  

    <tr> 
      <td height="20" align="right"> Upgrading Builder : </td>
      <td height="20" >
              <div id="upgrading_builderdiv" style="display:inline">
                <select name="upgrading_builder" id="upgrading_builder"  >
              <option value="">Please Select</option>
              </select></div>
         &nbsp;
      </td>
          <td height="20" align="right">Upgrading shipyard :</td>
      <td height="20" >
          <div id="upgrading_yarddiv" style="display:inline">
              <select name="upgrading_yard" id="upgrading_yard" >
                <option value="">Please Select</option>
              </select>
             </div>
             &nbsp;          
      </td>
    </tr>  


    <tr> 
      <td height="20" align="right"> Repair Builder : </td>
      <td height="20" >
              <div id="repair_builderdiv" style="display:inline">
                <select name="repair_builder" id="repair_builder"  >
              <option value="">Please Select</option>
              </select></div>
         &nbsp;
      </td>
          <td height="20" align="right">Repair shipyard :</td>
      <td height="20" >
          <div id="repair_yarddiv" style="display:inline">
              <select name="repair_yard" id="repair_yard" >
                <option value="">Please Select</option>
              </select>
             </div>
             &nbsp;          
      </td>
    </tr>         
      </table>  
现在,我想在提交表单时检查一些验证之后,清空此小节中的所有字段


一个是,我通过字段名称或id一个接一个地将字段设置为空白,但这样做并不好,我正在寻找较少的代码来完成这项工作。

如果要从TD中删除文本,可以使用jquery empty

编辑: 如果您指的是输入字段-

$('#tableID input[type="text"]').val(""); //will remove values from all input fields
也就是说,选择表中的所有文本输入,并将其值设置为空字符串。要包含select元素,请假设select元素的默认值为空字符串,如问题中的代码所示:

$('#yourTable').find('select,input[type="text"]').val("");

如果您提供了表id,您可以尝试重新发送字段

$('#tableID input[type=text]').val("");
$('#tableID input[type=password]').val("");
$('#tableID input[type=checkbox]').attr("checked", false);
$('#tableID input[type=radio]').attr("checked", false);
如果您有选择列表,第一个选项类似于选择值为0。那你就可以了

$('#tableID select').val("0"); 


哦,是的。。。到目前为止,你尝试了什么?实际上,我正在使用GETelEnMyByID或Doop.Frm(0).IdPieldFielsNeal.Value=每个字段。我怀疑这是空白字段的意思。把空白值放在这个子部分的所有字段中。我不想从子节中删除任何东西。只显示一个TabLeSUB部分,并将空白值放在所有字段中。@ Bajrang-Burn值到所有字段- $'TabLID输入[type=文本] '.Val.和隐藏表-$'tableID'。隐藏;
$('#tableID input[type=text]').val("");
$('#tableID input[type=password]').val("");
$('#tableID input[type=checkbox]').attr("checked", false);
$('#tableID input[type=radio]').attr("checked", false);
$('#tableID select').val("0"); 
$('#tableID select').val(('#tableID select option:eq(0)').attr("value"));