从html表单下拉选项列表中删除重复值

Vit*_*tal 4 forms jquery select options

我的问题是删除重复的选项值.从一开始,期权价值未知.当我选择城市时,则处理ajax请求并从该城市获取所有可用的分类.从这个"城市阵列"自动建立与街道的下拉列表.但当然有重复的选项值.那么,我怎么能删除它们?

<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>
Run Code Online (Sandbox Code Playgroud)

工作方式:

var foundedinputs = [];
    $("select[name=det_pas_object_gatve] option").each(function() {
      if($.inArray(this.value, foundedinputs) != -1) $(this).remove();
      foundedinputs.push(this.value);
    });
Run Code Online (Sandbox Code Playgroud)

Dar*_*jax 6

我自己做的是这样的:

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;
    }
});
Run Code Online (Sandbox Code Playgroud)