日期:2014-05-16  浏览次数:20359 次

用js怎么过滤相同值?
如题:有一个下拉框selectFlag,用js获得下拉框var selectFlag = document.getElementById('selectFlag');
然后遍历该下拉框:for(var i=0;i<selectFlag.length;i++){
  var current = selectFlag.options[i];
  if(current.value=="all"){ 
  for(var j=0;j<allmember.length;j++){
  var allList = allmember.options[j];
  if(!radioval.checked){
  if(allList.value==null || allList.value==""){
  idStr += "";
  }else{
  idStr += allList.value;
  }
  }else{
  idStr += allList.value + ",";
  }  
  count += 1;
  }
  break;
  }else{
  if(!radioval.checked){
  idStr += current.value;
  }else{
  idStr += current.value + ",";
  }
  count += 1;
  }
}
把下拉框所有选项的值放到idStr中,怎么把下拉框中相同的选项值过滤掉呢?

------解决方案--------------------
探讨
提示下思路

JScript code


if(idStr.indexOf(current.value)!=-1){
idStr += current.value + ",";
}
continue;