我试图从功能中的选择框中删除所选选项。下面的代码不起作用。我做错了什么?
function removeItem(refundItem) {
itemToDelete = document.getElementById("yourStuff").options[refundItem].text;
inCart = document.getElementById("yourCart").rows.length;
for (i = 1; i <= inCart; i++) {
maybeRefund = document.getElementById("yourCart").rows[i].cells[0].innerHTML;
maybeRefund = maybeRefund.trim();
if (itemToDelete == maybeRefund) {
refundPrice = document.getElementById("yourCart").rows[i].cells[2].innerHTML;
document.getElementById("yourCart").deleteRow(i);
Money.value = Number(Money.value) + Number(refundPrice);
document.getElementById("yourCart").deleteRow(i);
document.getElementById("yourStuff").options.remove(refundItem);
// document.getElementById("yourStuff").options.remove(selectedIndex);
}
}
document.getElementById("yourStuff").selectedIndex = 0;
}
答案 0 :(得分:0)
答案 1 :(得分:0)
应该是
..
document.getElementById("yourStuff").remove(refundItem);
..
即从select中删除索引为refundItem
的项目,ID为yourStuff
。有关详细信息,请参阅demo