单击按钮后刷新屏幕

时间:2011-09-06 08:32:23

标签: javascript html sharepoint

我目前有几个if语句在单击按钮刷新后填充特定表。

再次单击该按钮后,我需要删除上一个已解决的表。我怎么能这样做?

if (strDate == "Jan-2010") {
    var TableRowHtml = "<table id='box-table-a'>";
    TableRowHtml +="<TR><TH 'style='width: 50px'>OPERATIONS</TH></TR>";
    TableRowHtml +="<TR><TH 'style='width: 50px'>Unit Costs</TH></TR>";
    TableRowHtml +="<TR><TD>" + Total[0] + "</TD></TR>";
}
else if (strDate == "Feb-2010") {
    var TableRowHtml1 = "<table id='box-table-a'>";
    TableRowHtml1 +="<TR><TH 'style='width: 50px'>OPERATIONS</TH></TR>";
    TableRowHtml1 +="<TR><TH 'style='width: 50px'>Unit Costs</TH></TR>";
    TableRowHtml1 +="<TR><TD>" + Total[1] + "</TD></TR>"; 
}
else if (strDate == "Mar-2010") {
    var TableRowHtml2 = "<table id='box-table-a'>";
    TableRowHtml2 +="<TR><TH 'style='width: 50px'>OPERATIONS</TH></TR>";
    TableRowHtml2 +="<TR><TH 'style='width: 50px'>Unit Costs</TH></TR>";
    TableRowHtml2 +="<TR><TD>" + Total[2] + "</TD></TR>"; 
}
else if (strDate == "Apr-2010") {
    var TableRowHtml3  = "<table id='box-table-a'>";
    TableRowHtml3 +="<TR><TH 'style='width: 50px'>OPERATIONS</TH></TR>";
    TableRowHtml3 +="<TR><TH 'style='width: 50px'>Unit Costs</TH></TR>";
    TableRowHtml3 +="<TR><TD>" + Total[3] + "</TD></TR>"; 
}

下拉代码:

<tr><td><select id="combobox">
      <option value="Jan-2010">Jan/2010</option>
      <option value="Feb-2010">Feb/2010</option>
      <option value="Mar-2010">Mar/2010</option>
      <option value="Apr-2010">Apr/2010</option>
      <option value="May-2010">May/2010</option>
      <option value="Jun-2010">Jun/2010</option>
  </select></td>
  <td><input type="button" id="RefreshMetrics"  value="Refresh"></td>
</tr>
</select></td>
<td><input type="button" id="RefreshMetrics"  value="Refresh"></td>
</tr>
</table>

/////////////////////////////////////////////// //////////////////////////////

可以将以下代码放在每个特定的if语句中,例如...删除每个不需要的表...对于那个特定的月份

                      if (strDate == "Jan-2010") 

                    {


                   $('TableRowHtml1').last().remove();
                   $('TableRowHtml2').last().remove();
                   $('TableRowHtml3').last().remove();



       var TableRowHtml = "<table id='box-table-a'>";     
       TableRowHtml +="<TR><TH 'style='width: 50px'>OPERATIONS</TH></TR>";           
 TableRowHtml +="<TR><TH 'style='width: 50px'>Unit Costs</TH></TR>";                   TableRowHtml +="<TR><TD>" + Total[0] + "</TD></TR>";     
                }           

1 个答案:

答案 0 :(得分:1)

您可以使用Jquery删除API。

http://api.jquery.com/remove/

$('table').last().remove();