我在Chrome开发控制台得到以下错误:

Uncaught TypeError: Cannot read property 'msie' of undefined

我的理解是,这是因为.browser现在在jQuery中已弃用,但我使用的是最新版本的jQuery工具,它仍然会给出错误,我检查了js文件,它就在那里。

我怎样才能避免这个错误呢?


当前回答

将JS替换为

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

来源链接

其他回答

这个问题主要是由浏览器导航和版本属性引起的。 为此,你必须在函数中添加以下代码:

/* solution to undefined msie */
jQuery.browser = {};
jQuery.browser.msie = false;
    jQuery.browser.version = 0;
    if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
        jQuery.browser.msie = true;
        jQuery.browser.version = RegExp.$1;
    }
/* solution to undefined msie */    

例如,我正在使用它的点击功能,看到它:

 $(document).on('click', '.remove_add_test', function() {
    var product_id = $(this).data('id');
    var thisproduct = $(this);
    
    /* solution to undefined msie */
    jQuery.browser = {};
    jQuery.browser.msie = false;
        jQuery.browser.version = 0;
        if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
            jQuery.browser.msie = true;
            jQuery.browser.version = RegExp.$1;
        }
    /* solution to undefined msie */    
    
    jConfirm('Are you sure you want to delete record?', 'Remove Product', function(r) {
        if (r == true) {
            $.ajax({
                type: 'POST',
                url: 'scripts/ajax/index.php',
                data: {
                    method: 'removeproduct_fromcart',
                    id: product_id
                },
                dataType: 'json',
                success: function(data) {
                    if (data.RESULT == 0) {
                        $(".price span").text(data.totalprice);
                        $(thisproduct).closest('tr').remove();
                        $(".cart-number").text(data.productcount - 1);
                        $.growl.notice({
                            title: "Shopping Cart",
                            message: data.MSG
                        });
                       location.reload();
                        // window.location.href = 'https://www.youth-revisited.co.uk/payment.html';

                    }
                    // window.location.href = 'https://www.youth-revisited.co.uk/payment.html';
                }
            });
            // window.location.href = 'https://www.youth-revisited.co.uk/payment.html';

        } else {
            return false;
        }
    });
});

你可以看看AJ的解决方案。这非常简单,只需复制并粘贴下面的代码行。

jQuery.browser = {};
(function () {
    jQuery.browser.msie = false;
    jQuery.browser.version = 0;
    if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
        jQuery.browser.msie = true;
        jQuery.browser.version = RegExp.$1;
    }
})();

参考:

美元。jQuery 1.9浏览器。x表示遗留IE检测

因为我不打算支持旧的IE版本,我只是替换了所有对浏览器的引用。我爱虚伪。 我知道这不是个好办法,但对我来说很管用。

(实际上,它们以!browser的形式出现。Msie,可以从条件中省略。)

在jsp/js文件中使用以下脚本标记:

<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>

这肯定有用。

我在使用JQuery 1.10和JQuery UI 1.8时得到这个错误。我能够通过更新到最新的JQuery UI 1.11.4来解决这个错误。

从Visual Studio更新JQuery UI的步骤:

导航到项目或解决方案 右键单击:“管理NuGet包” 在左侧,单击“Installed Packages”选项卡 找到“JQuery UI (Combined library)”,然后单击Update 如果找到,选择它并单击Update 如果没有找到,请在左侧的“Online > nuget.org”选项卡中找到它,然后单击安装。如果旧版本的Jquery UI版本仍然存在,可以将其从项目中删除