简体   繁体   English

下拉列表更改功能在IE9中不起作用

[英]Drop down list change function not working in IE9

I have two dropdowns, the second dropdown shall change when something is changed in the first dropdown, this is working fine in Firefox, but not in IE. 我有两个下拉菜单,第二个下拉菜单在第一个下拉菜单中进行了更改时将发生变化,这在Firefox中工作正常,但在IE中却没有。 (IE9). (IE9)。 Then in the second dropdown, I'm looping through the items, and hiding some of them. 然后在第二个下拉菜单中,我遍历所有项目,并隐藏其中的一些项目。

var intermin = '${intermin}'; 
var intermin2=intermin.substring(1,3);

$('#startSemester').change(function() {

    var start=$('#startSemester').val();
    var end=$('#endSemester').val();
    var start1=start.substring(0,1);
    var start2=start.substring(1,3);
    var start3="";
    var end3="";
    if (start1=="H"){
        start3="2";
    }
    else
        start3="1";
    var start4=start2+start3;

    $('#endSemester option').removeAttr("disabled");
    var endSemesters= $('#endSemester');

        $.each($('option', endSemesters), function(index, value) { 
            var end= ($(this).val());
            var end2=end.substring(1,3);
            var end1=end.substring(0,1);
            if (end1=="H"){
                end3="2";
            }
            else
                end3="1";
            var end4=end2+end3;
            $('#endSemester ' + 'option' + '[value =' + end + ']').show();  
            if (end4 < start4 || end2 > intermin2) {
                $('#endSemester ' + 'option' + '[value =' + end + ']').hide();
            }
        });
});

Is there some way of having this working in IE. 是否有某种方式可以在IE中正常工作。

The problem with IE is the hiding option part. IE的问题是隐藏选项部分。 IE doesn't support much CSS on option elements. IE在选项元素上不支持太多CSS。 Especially display: none which is what .hide() does. 特别是display: none .hide()不会执行任何操作。

Therefor I believe it's best for you to disable the option. 因此,我认为最好禁用该选项。

var changeOption = $('#endSemester ' + 'option' + '[value=' + end + ']');

changeOption.prop("disabled", false);
if (parseInt(end4) < parseInt(start4) || parseInt(end2) > parseInt(intermin2)) {
    changeOption.prop("disabled", true);
}

You can test this in various browsers: http://jsfiddle.net/tive/wU6XL/ 您可以在各种浏览器中对此进行测试: http : //jsfiddle.net/tive/wU6XL/

Or if you're persistent enough find a plugin that: 或者,如果您足够坚持,请找到一个插件,该插件可以:

  • hides the select control and uses a replacement ul li structure 隐藏select控件并使用替换ul li结构
  • wraps <option /> with a span ( demo1 demo2 ) 包裹物<option />用跨度( demo1的 DEMO2

PS: you might want to change the option values accordingly since I have no view on your HTML. PS:您可能需要相应地更改选项值,因为我无法查看您的HTML。

Hey Please refer This code 嘿,请参考此代码

<asp:DropDownList ID="ddlWeeklyWeightIn" runat="server" ClientIDMode="Predictable">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
        </asp:DropDownList>

Js Code Is Js代码是

$('#ddlWeeklyWeightIn').on("change", function () {
            alert($(this).val());
        });

Please refer Link See Demo 请参考链接查看演示

Hope it helps you. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM