我的问题是删除重复的选项值。 从开始,选项值是未知的。当我选择城市时,然后正在处理ajax请求并获取该城市的所有可用分类信息。从这个“城市阵列”中自动构建带有街道的下拉列表。但是当然有重复的选项值。那么,我如何删除它们?从html表单下拉选项列表中删除重复的值
--- Choose street ---
Barrow
Hornets
Barrow
Stanley
Simon
Barrow
工作:
var foundedinputs = [];
$("select[name=det_pas_object_gatve] option").each(function() {
if($.inArray(this.value, foundedinputs) != -1) $(this).remove();
foundedinputs.push(this.value);
});
2012-02-20
Vital
+1
重复的问题:http://stackoverflow.com/questions/3227754/delete-duplicate-entries- from-a-select-box –
2012-02-20 18:19:55
+0
如果您有权访问它,那么在构建选择列表之前修改数据服务器端可能会更容易。 –
2012-02-20 18:22:51
+0
@Alexsuslin和Brian Glaz,谢谢。 –
2012-02-20 18:39:58