JavaScript去除数组中的重复值 100
varbmfzr="field14352";varfybmfzr="field14333";jQuery(document).ready(function(){//明细1...
var bmfzr = "field14352";var fybmfzr = "field14333";
jQuery(document).ready(function(){//明细1处理jQuery("#indexnum0").bind("propertychange",function(){bindFeeChange(1);});
bindFeeChange(2);
});
//给明细表字段绑定事件function bindFeeChange(m){var indexnum0 = 0;if(document.getElementById("indexnum0")){indexnum0 = document.getElementById("indexnum0").value * 1.0 - 1;}if(indexnum0>=0){if(m == 1){jQuery("#"+bmfzr+"_"+indexnum0).bind("propertychange",function(){setHrmResourceValue();});} else if(m == 2){ for(var k = 0 ; k <= indexnum0;k++){jQuery("#"+bmfzr+"_"+k).bind("propertychange",function(){setHrmResourceValue();});}}}}//循环明细表字段,将值赋值给主表字段function setHrmResourceValue(){var fybmfzr_v = "";var fybmfzr_s = "";var indexnum0 = 0;if(document.getElementById("indexnum0")){indexnum0 = document.getElementById("indexnum0").value * 1.0 - 1;}for(var i = 0 ; i <= indexnum0 ;i++){if(jQuery("#"+bmfzr+"_"+i)){var bmfzr_v = jQuery("#"+bmfzr+"_"+i).val();alert(bmfzr_v);if(bmfzr_v != null && bmfzr_v != ""){fybmfzr_v += "," + jQuery("#"+bmfzr+"_"+i).val();fybmfzr_s += " " + jQuery("#"+bmfzr+"_"+i+"span").html();}}}if(fybmfzr_v.length > 1){fybmfzr_v = fybmfzr_v.substring(1,fybmfzr_v.length);
}jQuery("#"+fybmfzr).val(fybmfzr_v);jQuery("#"+fybmfzr + "span").html(fybmfzr_s);}
以上是我选择了两次责任人,整改人员自动显示责任人的代码,然后问题就是有重复的姓名,该怎样在整改人员中只显示唯一的值呢,请直接给我写代码,不胜感激 展开
jQuery(document).ready(function(){//明细1处理jQuery("#indexnum0").bind("propertychange",function(){bindFeeChange(1);});
bindFeeChange(2);
});
//给明细表字段绑定事件function bindFeeChange(m){var indexnum0 = 0;if(document.getElementById("indexnum0")){indexnum0 = document.getElementById("indexnum0").value * 1.0 - 1;}if(indexnum0>=0){if(m == 1){jQuery("#"+bmfzr+"_"+indexnum0).bind("propertychange",function(){setHrmResourceValue();});} else if(m == 2){ for(var k = 0 ; k <= indexnum0;k++){jQuery("#"+bmfzr+"_"+k).bind("propertychange",function(){setHrmResourceValue();});}}}}//循环明细表字段,将值赋值给主表字段function setHrmResourceValue(){var fybmfzr_v = "";var fybmfzr_s = "";var indexnum0 = 0;if(document.getElementById("indexnum0")){indexnum0 = document.getElementById("indexnum0").value * 1.0 - 1;}for(var i = 0 ; i <= indexnum0 ;i++){if(jQuery("#"+bmfzr+"_"+i)){var bmfzr_v = jQuery("#"+bmfzr+"_"+i).val();alert(bmfzr_v);if(bmfzr_v != null && bmfzr_v != ""){fybmfzr_v += "," + jQuery("#"+bmfzr+"_"+i).val();fybmfzr_s += " " + jQuery("#"+bmfzr+"_"+i+"span").html();}}}if(fybmfzr_v.length > 1){fybmfzr_v = fybmfzr_v.substring(1,fybmfzr_v.length);
}jQuery("#"+fybmfzr).val(fybmfzr_v);jQuery("#"+fybmfzr + "span").html(fybmfzr_s);}
以上是我选择了两次责任人,整改人员自动显示责任人的代码,然后问题就是有重复的姓名,该怎样在整改人员中只显示唯一的值呢,请直接给我写代码,不胜感激 展开
1个回答
展开全部
Array.prototype.unique = function() {
var res = [], hash = {};
for(var i=0, elem; (elem = this[i]) != null; i++) {
if (!hash[elem])
{
res.push(elem);
hash[elem] = true;
}
}
return res;
};
数组去除重复,用法:
var a = [1,2,3,3,3,3,4];
alert(a.unique());
追问
特别感谢,但是我用unique没有效果,还有其他方法吗
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询