1
我創建了一個下拉表,在添加新行時從下拉列表中選擇某些內容時應刪除現有行。動態添加和刪除HTML表中的行
我可以添加,但我無法弄清楚如何刪除舊的。幫幫我!
var currencies;
$.ajax({
url: 'data.json',
type: "post",
dataType: "json",
method: "GET",
success: function (data, textStatus, jqXHR) {
currencies = data[0].currencies;
drawTable(currencies);
}
});
function drawTable(currencies) {
for (var i = 0; i < currencies.length; i++) {
drawRow(currencies[i]);
}
}
function IfTheyPicked5Days() {
if ($("#dropdown")[0].value=="fivedays") {
return true;
}
else {
return false;
}
}
function redrawTableForPeopleWhoPicked1Month() {
drawTable(currencies);
}
function drawRow(rowData) {
var row = $("<tr />")
$("#currencyhomework").append(row);
row.append($("<td>" + rowData.currency + "</td>"));
row.append($("<td>" + rowData.country + "</td>"));
row.append($("<td>" + rowData.ranges.oneday + "</td>"));
if (IfTheyPicked5Days()){
row.append($("<td>" + rowData.ranges.fivedays + "</td>"));
} else {
row.append($("<td>" + rowData.ranges.onemonth + "</td>"));
}
}
http://api.jquery.com/empty/ – 2015-01-09 18:40:21
http://api.jquery.com/remove/ – Buck3y3 2015-01-09 18:40:39