4
我的问题是删除重复的选项值。 从开始,选项值是未知的。当我选择城市时,然后正在处理ajax请求并获取该城市的所有可用分类信息。从这个“城市阵列”中自动构建带有街道的下拉列表。但是当然有重复的选项值。那么,我如何删除它们?从html表单下拉选项列表中删除重复的值
<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);
});
重复的问题:http://stackoverflow.com/questions/3227754/delete-duplicate-entries- from-a-select-box – alexsuslin 2012-02-20 18:19:55
如果您有权访问它,那么在构建选择列表之前修改数据服务器端可能会更容易。 – 2012-02-20 18:22:51
@Alexsuslin和Brian Glaz,谢谢。 – Vital 2012-02-20 18:39:58