$ (This) .attr (& ldquo; href & rdquo;) return …

I am trying to use bootbox with Twitter Bootsrap
.

In the code below when I use this.attr('href');
and I get TypeError: this.attr is not a function
.

When I change to $(this).attr('href');
i get Undefined
.

Delete user

 
    
    $(document).on("click", ".alert", function(e) {
        e.preventDefault();

        bootbox.confirm("Are you sure?", function(result) {

        if (result) {
            document.location.href = this.attr('href'); // doesn't work
            document.location.href = $(this).attr('href'); // Undefined
        }
    });

    });

Any idea?

That’s not your jQuery event callback function anymore, but the bootbox callback… try
$.proxy

to bind the context:

$(document).on("click", ".alert", function(e) {
    e.preventDefault();

    bootbox.confirm("Are you sure?", $.proxy(function(result) {
        if (result) {
            document.location.href = this.href;
        }
    }, this));
});
Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » $ (This) .attr (& ldquo; href & rdquo;) return …

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录