jQuery的ajaxStart [英] jQuery's ajaxStart

查看:94
本文介绍了jQuery的ajaxStart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这样的构造:

I am using such construction:

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

我想在用户每次单击时禁用提交"按钮.为了使其通用-我想在ajaxStart方法中做到这一点,那么有什么方法可以获取初始化请求的按钮的ID? 谢谢

And I want to disable submit button every time the user clicks on it. In order to make it universal - I want to do it in ajaxStart method, so is there any way to get the button's id which initialized the request? Thank you

推荐答案

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

Give all of your submit button a class, for example: submitBtn, then

$('.submitBtn').ajaxStart(function() {
  $(this).prop('disabled', true);
}).ajaxComplete(function() {
  $(this).prop('disabled', false);
});

这篇关于jQuery的ajaxStart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆