我试图从一个列表框中将选定内容复制(非复制)到另一个列表框时遇到一些问题。我总是收到“无法获取属性的值:对象为空或未定义”异常。无法获取属性'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