0
我试图防止从列表框中打印重复值到标签,这是我所做的,但显然它不是正确的,没有错误,但没有打印出来给我标签,如果我删除此行:Javascript +防止从列表框中打印出重复的值来标记
if (arSelected.indexOf(selectBox.option[i].selected == -1))
它打印出的值,但显然每次我点击,并突出显示在列表框中的值,它会再打印出来给我的标签。请提供建议。谢谢!
<select multiple size="8" style="width: 135px" onBlur="selectAl ('QualMemTypeToBox',true)" id="QualMemTypeToBox"></select>
function selectAll(selectBox, selectAll) {
var arSelected = "";
// have we been passed an ID
if (typeof selectBox == "string") {
selectBox = document.getElementById(selectBox);
}
// is the select box a multiple select box?
if (selectBox.type == "select-multiple") {
for (var i = 0; i < selectBox.options.length; i++) {
selectBox.options[i].selected = selectAll;
if (arSelected.indexOf(selectBox.option[i].selected == -1)) {
document.getElementById('<%=uilblDestinationQualMemType.ClientID%>').innerHTML += selectBox.options[i].value + " | ";
arSelected += selectBox.options[i].selected;
}
}
}
}
感谢您的评论的解释。有用。 – k80sg