0

我正在使用这样的结构:

$('#wait').ajaxStart(function() {
    if ($(this).not(':visible'))
        $(this).showWarning();
}).ajaxComplete(function() {
    if ($(this).is(':visible'))
        $(this).hideWarning();
}).ajaxError(function() {
    alert('Unexpected error...');
});

我想在用户每次点击它时禁用提交按钮。为了使其通用-我想在 ajaxStart 方法中执行此操作,那么有什么方法可以获取初始化请求的按钮 id?谢谢

4

2 回答 2

1

给所有提交按钮一个类,例如:submitBtn,然后

$('.submitBtn').ajaxStart(function() {
  $(this).prop('disabled', true);
}).ajaxComplete(function() {
  $(this).prop('disabled', false);
});
于 2012-04-04T06:16:49.660 回答
0

假设您可以将按钮单击事件传递给此处的函数,您可以这样做:

$('#wait').ajaxSend(function(event) {        //pass event object
  $(event.target).css('disabled','disabled');   //get event target
  if ($(this).not(':visible'))
        $(this).showWarning();
}).ajaxComplete(function() {
    if ($(this).is(':visible'))
        $(this).hideWarning();
}).ajaxError(function() {
    alert('Unexpected error...');
});
于 2012-04-04T06:02:57.983 回答