无法在ajaxStart中更改跨度文本

Cant change span text in ajaxStart

本文关键字:文本 ajaxStart      更新时间:2023-09-26

jquery 2.2.3

我有一个ajaxstart方法,我想在显示我的模态之前更新跨度的文本:

       $(document).on({
    ajaxStart: function () {
        $('#spnModalProgress').html("I should change");
        $('#spnModalProgress').show();
    },
    ajaxStop: function() {
      $('#spnModalProgress').hide();
    }
});

这是html:

  <div class="modal">
  </div>
<span id="spnModalProgress" class="centerModaltext">Get rid of this text</span>  

当我进行ajax调用时,代码正在启动,但span文本根本没有改变。我的模态窗口会出现,但我把代码拿出来证明它不会干扰跨度。事实上,我根本无法操纵跨度。当我告诉它显示时,它不会显示。如何在ajaxStart中更改文本?如果我能克服这一点,我相信我想做的其他事情也会落实到位。感谢

我已经复制了你的代码并进行了ajax调用,它对我很有效。

       $(document).on({
    ajaxStart: function () {
        $('#spnModalProgress').html("I should change");
        $('#spnModalProgress').show();
    },
    ajaxStop: function() {
      setTimeout(function(){$('#spnModalProgress').hide()}, 2000);
    }
});
$.get('url');
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<div class="modal">
</div>
<span id="spnModalProgress" class="centerModaltext">Get rid of this text</span>