2012-07-30 83 views
0

我有一個如此之大的表單,估計有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將字段逐個空白,但它不會很好地完成這項工作,我正在尋找更少的代碼來完成這項工作。

+1

哦,是的。 .. 你試過什麼了? – 2012-07-30 12:27:17

+0

其實我正在用getElementById或document.form [0] .inputfielsName.value =''爲每個字段。 – Bajrang 2012-07-30 12:30:52

回答

0

如果您提供表格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"); 

$('#tableID select').val(('#tableID select option:eq(0)').attr("value")); 
1

如果你想從TD刪除文本,你可以使用jQuery empty()

$('#tableID td').empty(); // will remove the text 
$('#tableID td').hide(); // will hide the text 

編輯: 如果你指的是輸入字段 -

$('#tableID input[type="text"]').val(""); //will remove values from all input fields 
+0

我懷疑這是什麼意思是「空白所有領域」。 – 2012-07-30 12:30:04

+0

將空白值(「」)置於此子部分中的所有字段。 – Bajrang 2012-07-30 12:33:28

+0

我不想從子部分中刪除任何東西,只顯示沒有表(子部分),並將空白值到所有字段。 – Bajrang 2012-07-30 12:36:10

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

也就是說,選擇表中的所有文本輸入並將其值設置爲空字符串。要包含select元素,假設您選擇的元素的默認值是空字符串,如問題中的代碼所示:

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