.remove () or selector behavior in IE

function updateSelector()
{
    //select all drop down list of field selector
    var fieldSelector = $("select:not(#project):not(#allNo):not(#availableNo)");
    var selected;
    //copy full option list from static drop down list to temp drop down list
    $("#availableNo").empty().append($("#allNo").clone());
    //remove any selected option from temp option
    fieldSelector.each(function() {
        $("#availableNo"+" option[value="+$(this).val()+"]").remove();
    });
    //copy temp option to all field selector
    fieldSelector.each(function() {
        //store selected option for current dropdown
        selected = $("option:selected", this);
        //clear list then append stored selected option
        $(this).empty().append(selected);
        //append temp option to current dropdown
        $(this).append($("#availableNo option").clone());
        //add blank option
        if($("option",this).length ==1)
            $(this).append("<option></option>");
    });
    //alert("..");
}

The above code works fine, but in IE it seems that it will behave strangely if there is an instruction after it (no problem, if there is no statdment after it, and only IE has problems with it).

If I warn (in the last line), the selected parameter will be moved by 1 index.

For example, if there is 1-4, choice 1 will lead to choice 2; if you select 2, it will be 3.

Does anyone know why or what causes this?

I am really disappointed with this.

+3
source share
1 answer

This case is the same as this case.

solve by adding "this.blur ();" before the expression val ()

fieldSelector.each(function() {
   this.blur();
   $("#availableNo"+" option[value="+$(this).val()+"]").remove();
});
+1
source

All Articles