通过'this'来警告

时间:2014-10-21 19:07:47

标签: javascript jquery alertify

我想在使用类“找到”div中的按钮后使用alertify.js .removeRow

  $(".removeRow").find("button").click(function(){
            alertify.confirm("remove this field?", function (e) {
                if (e) {
                    // user clicked "ok"
                    $(this).closest(".agrRow").remove();
                }
            });     
  });

问题是在我调用alertify之后,我放松了“this”的值。 如何将“this”传递给alertify函数?

1 个答案:

答案 0 :(得分:4)

$(".removeRow").find("button").click(function(){
    var temp = this;
    alertify.confirm("remove this field?", function (e) {
        if (e) {
            // user clicked "ok"
            $(temp).closest(".agrRow").remove();
        }
    });     
});