Javascript+;防止将列表框中的重复值打印到标签
我试图阻止将重复的值从列表框打印到标签上,这是我所做的,但显然是不对的,没有错误,但没有打印到标签上,如果我删除这一行:Javascript+;防止将列表框中的重复值打印到标签,javascript,asp.net,vb.net,Javascript,Asp.net,Vb.net,我试图阻止将重复的值从列表框打印到标签上,这是我所做的,但显然是不对的,没有错误,但没有打印到标签上,如果我删除这一行: if (arSelected.indexOf(selectBox.option[i].selected == -1)) 它会打印出这些值,但很明显,每次我单击并突出显示列表框中的值时,它都会将它们再次打印到我的标签上。请提出忠告。谢谢 <select multiple size="8" style="width: 135px" onBlur="selectAl ('Q
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;
}
}
}
}
功能selectAll(selectBox,selectAll){
var=”;
//我们有身份证吗
如果(选择框的类型==“字符串”){
selectBox=document.getElementById(selectBox);
}
//选择框是否为多个选择框?
如果(selectBox.type==“选择多个”){
对于(变量i=0;i
试试:
功能选择全部(选择框,选择全部){
var=”;
//我们有身份证吗
如果(选择框的类型==“字符串”){
selectBox=document.getElementById(selectBox);
}
//每次调用函数时重置标签
document.getElementById(“”).innerHTML=“”;
//选择框是否为多个选择框?
如果(selectBox.type==“选择多个”){
对于(变量i=0;i
function selectAll(selectBox, selectAll) {
var arSelected = "";
// have we been passed an ID
if (typeof selectBox == "string") {
selectBox = document.getElementById(selectBox);
}
//reset the label every time the function is called
document.getElementById('<%=uilblDestinationQualMemType.ClientID%>').innerHTML="";
// 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;
//make sure you process only items that have been checked
//AND you need to track the VALUE of the <option>
//NOT the "selected" attribute
if (selectBox.options[i].selected && arSelected.indexOf(selectBox.options[i].value) == -1) {
document.getElementById('<%=uilblDestinationQualMemType.ClientID%>').innerHTML += selectBox.options[i].value + " | ";
//here is where you actually update the variable with the VALUE
//of the <option>, not the "selected" attribute
arSelected += selectBox.options[i].value;
}
}
}
}