简体   繁体   中英

JavaScript/jQuery stopped functioning in IE

I have the following script:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $(this).find("[id$='Panel']").hide();
        $(".toggleDisplay").change(function () {
            var groupName = $(this).find(":radio").attr('name');
            var ans = $('input[name="' + groupName + '"]:radio:checked').val();
            var displaylist = ["1", "2", "3", "4", "5"];
            if (displaylist.indexOf(ans) > -1) {
                $(this).find("[id$='Panel']").show();
            } else {
                $(this).find("[id$='Panel']").hide();
            }
        });
    });
</script>

When I inserted/tested this last week, it worked fine in IE 11. Today, it stopped working. However, it still works in Chrome. The IE error I receive is: "Object doesn't support property or method 'indexOf'"

I attempted to rewrite the if statement as follows, with no luck:

if ($.inArray(ans, displayList) != -1) {}

Any suggestions?

EDIT: The issue was my browser (somehow) reverting back to rendering as IE 8. Seems that this is a company wide issue. To prevent further hiccups, is there a painless method of doing this script in IE 8-compatible code?

A plausible guess is that you've somehow bumped your version of IE to emulate IE8, which doesn't support indexOf() (see Why doesn't indexOf work on an array IE8? ). You can do this (accidentally or otherwise) in various ways - see this answer here: https://stackoverflow.com/a/17877416/68231 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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