我目前有几个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>";
}