从html表单下拉选项列表中删除重复的值 [英] Deleting duplicated values from html form drop-down option list
本文介绍了从html表单下拉选项列表中删除重复的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是删除重复的选项值. 从一开始,选项值是未知的.当我选择城市时,正在处理ajax请求并从该城市获取所有可用分类.从该城市阵列"中自动构建带有街道的下拉列表.但是,当然有重复的选项值.那么,如何删除它们?
My problem is in deleting duplicated option values. From begining, options values are unknown. When I selecting the city, then is processing ajax request and getting all available classifieds from that city. From this "city array" is automatically building drop-down list with streets. But there of course are duplicated option values. So, how I can delete them?
<select name="det_pas_object_gatve" class="det_pas_object_select_css">
<option selected="selected" value="">--- Choose street ---</option>
<option value="Barrow">Barrow</option>
<option value="Hornets">Hornets</option>
<option value="Barrow">Barrow</option>
<option value="Stanley">Stanley</option>
<option value="Simon">Simon</option>
<option value="Barrow">Barrow</option>
</select>
工作:
var foundedinputs = [];
$("select[name=det_pas_object_gatve] option").each(function() {
if($.inArray(this.value, foundedinputs) != -1) $(this).remove();
foundedinputs.push(this.value);
});
推荐答案
我自己是这样的:
var seen = {};
jQuery('.det_pas_object_select_css').children().each(function() {
var txt = jQuery(this).clone().wrap('<select>').parent().html();
if (seen[txt]) {
jQuery(this).remove();
} else {
seen[txt] = true;
}
});
这篇关于从html表单下拉选项列表中删除重复的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文