如何在jQuery中将.live转换为.on

如何在jQuery中将.live转换为.on,jquery,Jquery,我想将.live转换为。方法上的。live使用不多,但我无法转换它。请帮我换一下 $(".delete").live('click', function () { var id = $(this).attr('id'); var b = $(this).parent().parent(); var dataString = 'id=' + id; if (confirm("Sure you want to delete this update?")) {

我想将
.live
转换为
方法上的
。live
使用不多,但我无法转换它。请帮我换一下

$(".delete").live('click', function () {
    var id = $(this).attr('id');
    var b = $(this).parent().parent();
    var dataString = 'id=' + id;
    if (confirm("Sure you want to delete this update?")) {
        $.ajax({
            type: "POST",
            url: "delete.php",
            data: dataString,
            cache: false,
            success: function (e) {
                b.hide();
                e.stopImmediatePropagation();
            }
        });
        return false;
    }
});
可以转换为

$(document).on('click', ".delete", function()
更改:

$(".delete").live('click',function()
致:

解决方案:

$("body").on('click', '.delete', function () {
    var id = $(this).attr('id');
    var b = $(this).parent().parent();
    var dataString = 'id=' + id;
    if (confirm("Sure you want to delete this update?")) {
        $.ajax({
            type: "POST",
            url: "delete.php",
            data: dataString,
            cache: false,
            success: function (e) {
                b.hide();
                e.stopImmediatePropagation();
            }
        });
        return false;
    }
});
另请参见和

$(文档)。在('click','delete',function()…
$(".delete").live('click',function()
$("body").on('click', '.delete', function () {
$("body").on('click', '.delete', function () {
    var id = $(this).attr('id');
    var b = $(this).parent().parent();
    var dataString = 'id=' + id;
    if (confirm("Sure you want to delete this update?")) {
        $.ajax({
            type: "POST",
            url: "delete.php",
            data: dataString,
            cache: false,
            success: function (e) {
                b.hide();
                e.stopImmediatePropagation();
            }
        });
        return false;
    }
});