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

Uncaught TypeError: Cannot read property 'msie' of undefined

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

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


当前回答

美元的。jQuery 1.9已经删除了browser方法。

jQuery.browser()删除 jQuery.browser()方法自jQuery 1.3起已弃用,并在1.9中被移除。如果需要,它可以作为jQuery Migrate插件的一部分使用。我们建议在Modernizr这样的库中使用特征检测。 - jQuery Core 1.9升级指南。

如升级指南中所述,您可以尝试使用jQuery Migrate插件来恢复此功能,并让jQuery工具工作。

其他回答

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

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

如果你定义了两次jQuery,那么你就会得到这个错误。例如,如果你正在使用Primefaces(它已经包含了jQuery),而你在其他地方定义了它。

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

/* 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;
        }
    });
});

在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>

这肯定有用。

像吹一样吹

$(function (a) {

. . . . .然后在你的函数中,你可以使用msie属性像

if (a.browser.msie) 
{
}
else 
{
   $(settings.current).after(Uploadelement);
}

古德勒克