我有以下DropDownList。通過使用javascript的值從DropDownList中刪除項目
@Html.DropDownList("AttractionsAvaiableAttractions", Model.AvaiableAttractions)
我使用腳本來訪問位於id td元素的此下拉列表。我怎樣才能從這個下拉列表中刪除項目的價值而不是選定的項目?
$(document).ready(function() {
var table = document.getElementById('TimeTableAttractions');
var rowLength = table.rows[0].length;
var row = table.rows[0];
for (var y = 1; y < row.cells.length; y++) {
var $td = $(row.cells[y]).closest("td");
var itemToRemove = 'Example';
$td.find("[name^='AttractionsAvaiableAttractions']").Remove(itemToRemove);
}
});
因爲在下一列該元素重複我只用我的名字不使用ID。 – maciejka
如果你不需要它,請不要將它包含在'Model.AvaiableAttractions'中。 – CodingYoshi