jQuery没有得到属性值

时间:2017-10-28 05:26:34

标签: javascript jquery

jQuery的:

$(".close_invoice").confirm({
    title: 'Are you sure to delete it?',
    content: 'Click to Delete if you are sure else click on Close.',
    type: 'red',
    typeAnimated: true,
    buttons: {
        delete: {
            text: 'Delete',
            btnClass: 'btn-red',
            action: function() {
                alert($(this).attr("id"));
            }
        },
        close: {
            text: 'Close',
            btnClass: 'btn-blue',
            action: function() {}
        }
    }
});

HTML:

<button class="btn btn-sm green btn-outline filter-submit margin-bottom close_invoice" id="14" jc-attached="true"><i class="fa fa-times"></i> Close Invoice</button>

任何人都可以告诉我为什么不采用属性ID的值。如何获取属性ID的值?它警告未定义。

1 个答案:

答案 0 :(得分:1)

您无法在this中使用function object parameters选择器..您可以将此value保存到变量中,然后将其设为function paramater object's value