我有以下工作正常:
$(".new_comment").ajaxStart(function() {
ajaxBanner('show');
// Disable button
$("input[type=submit]", this).attr("disabled", true);
});
$(".new_comment").ajaxComplete(function() {
ajaxBanner('hide');
// Re-enable button
$("input[type=submit]", this).removeAttr("disabled");
});
问题是只有当页面以评论表单呈现时才有效。在许多情况下,评论表单是动态注入(inject)到页面上的,然后就会失败。
如何使上面的live()生效?
谢谢
最佳答案
这尚未经过测试,但也许值得一试?
$(".new_comment").live("ajaxComplete", function() {
ajaxBanner('show');
// Disable button
$("input[type=submit]", this).attr("disabled", true);
});
另一种方法是在动态注入(inject)评论表单时添加事件,但我们需要为此添加更多代码(即注入(inject)发生的位置)。
关于jQuery ajaxStart 和 ajaxComplete 上线了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4240342/