【问题标题】:Show/Hide Selected option from Dropdown list in IE8 not working从 IE8 的下拉列表中显示/隐藏选定的选项不起作用
【发布时间】:2012-09-12 11:27:06
【问题描述】:

我正在尝试在 Dropdownlist 上执行显示/隐藏机制。这种情况是,一旦从 Dropdownlist 中选择了该值,则该值不应再在第二个 Dropdownlist 上可用。

该代码适用于 Firefox,但不适用于 IE8。 这是代码

<select id="dropdownone" class="" name="dropdownone">
<option selected="selected" value="">Default</option>
<option value="1">question 1?</option>
<option value="2">question 2</option>
<option value="3">question 3</option>
</select>

<select id="dropdowntwo" class="" name="dropdowntwo">
<option selected="selected" value="">Default</option>
<option value="1">question 1?</option>
<option value="2">question 2</option>
<option value="3">question 3</option>
</select>

$("#dropdownone").bind('change', function () {
            var index = this.selectedIndex;
            if (this.value != "") {
                $("#dropdowntwo option").each(function () {
                    var disabled = (this.index == index);
                    //$(this).attr("hidden", disabled);
                    if (disabled ) {
                        $(this).css('visibility', 'hidden');
                    } else {
                        $(this).show();
                    }
                });
            }
        });

【问题讨论】:

  • $("#dropdownone").bind('change', function () { var firstDropDown = this.selectedIndex; if (this.value != "") { $("#dropdowntwo 选项").each(function () { if(this.index == firstDropDown) { $("#dropdowntwo option[value='" + firstDropDown + "']").attr("style", "visibility: hidden; "); } else { $("#dropdowntwo option[value !='" + firstDropDown + "']").attr("style", "visibility: show;"); } }); } });我已经检查了 IE8,它对我来说工作正常。可能这个解决方案会对你有所帮助。请让我知道。谢谢。

标签: drop-down-menu internet-explorer-8 hide show


【解决方案1】:

你可以试试:

$("#dropdownone").bind('change', function () {
var firstDropDown = this.selectedIndex;

if (this.value != "") {              
    $("#dropdowntwo option").each(function () {
        if(this.index == firstDropDown) {
            $("#dropdowntwo option[value='" + firstDropDown + "']").attr("style", "visibility: hidden;");
        } else {
            $("#dropdowntwo option[value !='" + firstDropDown + "']").attr("style", "visibility: show;");
        }
    });
}
});

我已经检查过这在 IE8 中是否有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 2021-05-15
    相关资源
    最近更新 更多