Php 删除下拉列表中的重复项

Php 删除下拉列表中的重复项,php,javascript,jquery,html,Php,Javascript,Jquery,Html,我对dropdownlist ie teamsize进行了硬编码并添加了项目,如1,2,3 当我加载这个dropdownlist进行编辑/更新时,我会得到类似这样的重复值 一, 一, 二, 三, 4。。。如何消除此重复值 请在下面查找代码 <select name="anesthesia" id="selectAnesthesiaVal" style="width:25%;" class="required safe" AppendDataBoundItems = "fa

我对dropdownlist ie teamsize进行了硬编码并添加了项目,如1,2,3

当我加载这个dropdownlist进行编辑/更新时,我会得到类似这样的重复值

一,

一,

二,

三,

4。。。如何消除此重复值

请在下面查找代码

         <select name="anesthesia" id="selectAnesthesiaVal" style="width:25%;" class="required safe" AppendDataBoundItems = "false">
          <option value="<?php echo isset($event)?$event->proc_anesthesia_type:"" ;?>"><?php echo isset($event)?$event->proc_anesthesia_type:"" ;?></option><option value="General">General</option>
          <option value="Mac">Mac</option>
          <option value="Spinal/Epidural">Spinal/Epidural</option>
          <option value="Regional">Regional</option>
          <option value="Local">Local</option>
          <option value="Other">Other</option>
        </select>

我怀疑那条线


如果您不想使用jQuery来实现此目的,那么我建议将所有可能的值放入一个数组中,并在PHP中循环使用它们。如果该值存在,则只放置一次

此外,如果您想使用jQuery,而PHP在您的情况下是不可能的,那么请告诉我,我将发布一些jQuery

更新

这样就行了。我已经清楚地列出了评论,以逐步解释正在发生的事情。希望这有帮助

请注意,在PHP中执行此操作效率更高

// Set the present object
var present = {};
$('#selectAnesthesiaVal option').each(function(){
    // Get the text of the current option
    var text = $(this).text();
    // Test if the text is already present in the object
    if(present[text]){
        // If it is then remove it
        $(this).remove();
    }else{
        // Otherwise, place it in the object
        present[text] = true;
    }
});

“硬编码的dropdownlist”的代码是什么?如果它是“硬编码的”,您如何编辑/更新它?使用jQuery.each()循环遍历每个元素并测试是否存在具有相同值的其他元素。如果是这样,请使用jQuery.remove()将其删除。当然,最好首先了解您是如何获得重复项的。@ben Carey感谢您的回复,我从php中的数据库中获取值,因此如何使用jQuery进行此操作。你能帮我写代码吗