我需要隔离在 jQuery 中单击按钮时附加到按钮的值。但是,我还需要将点击处理程序包装在 $.proxy(...)
中,以便为后续函数调用维护上下文:
$('#' + tab.buttonId).click($.proxy(function() {
this.pop($(this).val());
}, this));
- this.pop 需要应用于对象
- $(this).val() 需要来自按钮
如何使每次调用 this
引用正确的内容?
最佳答案
您可以使用e.target
它将指向按钮对象:
$('#' + tab.buttonId).click($.proxy(function(e) {
this.pop($(e.target).val());
}, this));
关于javascript - 控制 jQuery 按钮代理函数中的上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31416404/