我試圖從一個列表框中將選定內容複製(非複製)到另一個列表框時遇到一些問題。我總是收到「無法獲取屬性的值:對象爲空或未定義」異常。無法獲取屬性'2'的值:對象爲空或未定義
下面是我的代碼
function CopyItem(from, to) {
var src = document.getElementById(from);
var dest = document.getElementById(to);
for (var i = 0; i < src.options.length; i++) {
if (src.options[i].selected) {
var found = false;
for (var j = 0; j < dest.options.length; j++) {
if (dest.options[j].value == src.option[i].value) {
found = true;
break;
}
}
if (!found) {
var newOption = document.createElement("option");
newOption.text = src.options[i].text;
newOption.value = src.options[i].value;
dest.options[dest.options.length] = newOption;
}
}
}
}
@Html.ListBox("lvDataList", Model.DataList, new { id = "SelectionList", Multiple = "multiple", Size = 15, style = "width: 100%;" })
@Html.ListBoxFor(x => x.SelectedData, Model.SelectedDataList, new { id = "SelectedList", Multiple = "multiple", Size = 15, style = "width: 100%;" })
<input type="button" id="btnAdd" title="Add Selected Events" onclick="CopyItem('SelectionList', 'SelectedList', true)" />
能有人請解釋錯在那裏做我的代碼? 謝謝。
哦。謝謝。現在它工作 – user1599647