0

我有一个带有一些值的下拉选择,以及一个克隆该下拉列表的按钮,因此我可以添加多个下拉列表以在其中设置值。在克隆的下拉列表中选择的值不应该在其他下拉列表中可用,如果我更改选择的值(以防用户改变主意)它应该更新其他下拉列表。我怎样才能用 jquery 完成这个?

    <select class="firstCallDropDown" name="contactTypes">
<option value="1">Home</option>
<option value="2">e-mail</option>
<option value="3">Mobile</option>
<option value="4">Mobile2</option>
<option value="5">Work</option>
</select>

<a href ="#" id=addContactNumber>Add</a>

jQuery:

$("#calls_column").delegate("#addContactNumber", "click", function(event) {
            var firstDrop = $(".firstCallDropDown:first");
            var clonedDrop = firstDrop.clone();
            clonedDrop.find("option:selected").removeAttr("selected");
            clonedSip.appendTo("#numbers");
            refreshDropdowns();

        });

function refreshDropdowns(){
   var values = $("select[name='contactTypes']");

            $(values).each(function () {
                var text = $(this).children('option:selected').val();
                var options = $("option[value='" + text + "']:not(:selected)");

                $(options).each(function () {
                    $(this).remove();
                });
            });
}

这就是我到目前为止所拥有的!

4

0 回答 0