“对象不支持属性或方法'find'"在IE中 [英] "Object doesn't support property or method 'find'" in IE

查看:727
本文介绍了“对象不支持属性或方法'find'"在IE中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

    <script>

        $(document).ready(function () {


            var data = [{
                "Id": "SWE",
                "Country": "Sweden",
                "Population": 9592552
            }, {
                "Id": "NOR",
                "Country": "Norway",
                "Population": 5084190
            }];


            function display(e) {
                alert("E" + e);
                var countryData = data.find(function (element, index, array) {
                    return element.Id === e;
                });
                alert(countryData.Population);
            }
            display('SWE');


        });


    </script>
</head>
</html>

上面发布的代码在Firefox和Chrome上运行正常,但我在Internet Explorer中收到错误消息。错误消息:

The code posted above is working properly on Firefox and Chrome but I get an error in Internet Explorer. Error message:

对象不支持属性或方法'find'

推荐答案

您正在使用JavaScript array.find()方法。请注意,这是标准的JS,与jQuery无关。事实上,你问题中的整个代码根本就不使用jQuery。

You are using the JavaScript array.find() method. Note that this is standard JS, and has nothing to do with jQuery. In fact, your entire code in the question makes no use of jQuery at all.

你可以找到 array.find()<的文档/ code>此处: https://developer.mozilla.org/ en / docs / Web / JavaScript / Reference / Global_Objects / Array / find

如果滚动到本页底部,你会注意到它有浏览器支持信息,你会看到它声明IE不支持这种方法。

If you scroll to the bottom of this page, you will note that it has browser support info, and you will see that it states that IE does not support this method.

具有讽刺意味的是,你最好的方法是使用jQuery,它确实有所有浏览器都支持类似的功能。

Ironically, your best way around this would be to use jQuery, which does have similar functionality that is supported in all browsers.

这篇关于“对象不支持属性或方法'find'&quot;在IE中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆