0

我有一个更改下拉菜单,会出现一个弹出窗口,并警告更改值会产生一些影响。当用户选择否时,下拉选择的索引应该返回到初始选择的选项。这就是我所做的:

function closeDeleteVariantsPopup(){
        parent.$.fn.colorbox.close();
        var elementSpecies= parent.document.getElementsByClassName("speice");
        for(var i = 0;i<elementSpecies[0].options.length; ++i) {
            alert(parent.document.getElementById("speciesHiddenValue").value);
            if(elementSpecies[0].options[i].id === parent.document.getElementById("speciesHiddenValue").value) {
                alert(parent.document.getElementById("speciesHiddenValue").value);
                elementSpecies[0].selectedIndex = i;
                break;
            }
        }
    }

html & freemarker:

[@spring.bind "genomicReferenceBean.specie.id"/]
<select name="specie.id" id="specie.id"  [#if !(genomicReferenceBean.specie?has_content) || genomicReferenceBean.specie.id==-1] multiple="multiple" [/#if] class='speice singleList'  onchange='getMaterials()' >
[#if genomicReferenceInitializerBean.species?has_content]
    [#list genomicReferenceInitializerBean.species as initializerValueBean]
        <option for="selectSpecie" name="${initializerValueBean.name}" [#if genomicReferenceBean.specie?has_content && genomicReferenceBean.specie.id?number == initializerValueBean.id] selected="selected" [/#if] value="${initializerValueBean.id}">${initializerValueBean.name}</option>
    [/#list]
[/#if]

</select>
<input type="hidden" id="speciesHiddenValue" value="${genomicReferenceBean.specie.id?number}"/>

现在当我按下没有按钮时弹出关闭并且没有任何反应

4

1 回答 1

0

我使用了 jQuery,它运行良好:

parent.$(".speice option").each(function(){
            if($(this).val() === parent.document.getElementById("speciesHiddenValue").value) {
                $(this).attr('selected', 'selected');
            }
        });
于 2013-05-09T11:34:38.510 回答