我想在第一次点击后解除 anchor 的绑定(bind),但是当用户点击特定按钮时,我想将点击事件重新绑定(bind)到该 anchor
这段代码是我写的
$(document).ready(function(){
$("a.package").click(function(){
//alert('click');
$(this).unbind('click');
// the rest of the code
});
$('#activate').click(function(){
$('a.package').bind('click');
// the rest of the code
});
});
unbind 功能可以正常使用,但是bind 功能却不能使用,为什么?以及如何让它发挥作用?
最佳答案
将您的点击函数存储在变量中,以便可以轻松地重新分配...
$(document).ready(function() {
var onclick = function(e) {
//alert('click');
$(this).unbind('click');
// the rest of the code
}
$("a.package").click(onclick);
$('#activate').click(function() {
$('a.package').click(onclick);
// the rest of the code
});
});
关于jquery - 解除绑定(bind)后如何重新绑定(bind)点击事件到 anchor ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6616214/