Jquery 为什么它在1.9.1版中不起作用?

Jquery 为什么它在1.9.1版中不起作用?,jquery,version,this,undefined,Jquery,Version,This,Undefined,我不知道为什么,但是这段代码在版本1.9.1中不起作用。问题是,对于AJAX调用的新结构,我应该切换到版本1.9.1,但是当我这样做时,这个函数中的this是未定义的 谢谢你的帮助 $(document).on('click', 'input.addCart', function () { // Récupère le partType sélectionné. var $partType = $(this).closest('.partType'); var par

我不知道为什么,但是这段代码在版本1.9.1中不起作用。问题是,对于AJAX调用的新结构,我应该切换到版本1.9.1,但是当我这样做时,这个函数中的
this
是未定义的

谢谢你的帮助

$(document).on('click', 'input.addCart', function () {

    // Récupère le partType sélectionné.
    var $partType = $(this).closest('.partType');

    var parameters = {
        "serial_glider": serial_glider,
        "partType_id": $partType.data('partType_id')
    };

    $.get('protected/addToCart.php', parameters)
        .done(function (data) {

            // Vérifie que les propriétés de l'objet JSON ont bien été créées et
            // vérifie si la requête fut un succès.
            if (data.hasOwnProperty('success') &&
                data['success'] &&
                data.hasOwnProperty('partType_quantity')) {
                updatePartType(data['partType_quantity'], $partType.find('.buttons'));

                // Vérifie que la propriété de l'objet JSON a bien été créée.
            } else if (data.hasOwnProperty('message')) {

                // Affiche un message d'erreur expliquant l'échec de la requête.
                alert(data['message']);
            } else {
                alert('Communication with the server failed.');
            }
        }).fail(function () {
            alert('Communication with the server failed.');
        })
});

你是说
这个
是未定义的,还是
$(this).closest('.partType')的结果?您在控制台中看到的确切错误消息是哪一行?如果jQuery被正确地包含在
中,那么这个
本身就不应该是未定义的。你说得对!你指对了线。在服务器端,我没有得到
partType\u id
参数。当我执行
警报($(this).className)
时,结果是未定义的。相同的代码(成功回调内部)在版本1.4.4中工作。
className
不会在jQuery包装的对象上工作,因为它是JavaScript属性。使用:
this.className
或在jQuery包装对象上使用jQuery
attr
$(this.attr('class')对不起。。。在我的真实代码中,我写得很好。