在Bootstrap确认中使用.closest()。attr()访问数据属性不起作用

时间:2015-09-22 09:08:05

标签: javascript jquery twitter-bootstrap

我有以下HTML:

<div data-fleet-id="438935" class="col-lg-6 col-md-8 col-sm-12 col-xs-12 list-wrap">
    <a data-toggle="confirmation" data-placement="top" class="list-item-link-1" title="" data-original-title="Delete List">
        <span class="label label-danger">
            <i class="fa fa-times"></i>
        </span>
    </a>
    </h3>
</div>

我包括Bootstrap和Bootstrap Confirmation脚本,然后添加以下代码以启用Bootstrap确认:

$(document).ready(function () {
    $('.list-item-link-1').confirmation({
        onConfirm: function () {
            var list_id = $(this).closest(".list-wrap").attr("data-fleet-id");
            $.ajax({
                type: "POST",
                url: "server/delete_list.php",
                data: {
                    'list_id': list_id
                },
                cache: false,
                success: function (data) {},
                error: function () {
                    alert("AJAX error.");
                }
            });
        },
        btnOkLabel: '<i class="icon-ok-sign icon-white"></i>',
        btnCancelLabel: '<i class="icon-remove-sign"></i>'
    });
});

问题是我无法访问data-fleet-id课程的.list-wrap。 var值实际上是undefined

这是console.log($(this))结果:

enter image description here

0 个答案:

没有答案