更改按钮的文字

时间:2019-07-08 16:59:50

标签: jquery button text fade

我正在做一个项目,我必须更改带有淡入淡出效果的按钮的文本。但是我做不到。我应该单击按钮,它的文本应该淡出,并且它们与其他文本一起淡入。我为此使用jQuery

$("#button_fade").on("click", function(){
    if($(this).text() == "HELLO") {
         $(this).text().fadeOut(function(){
             $(this).text("WORLD").fadeIn();
         });
    }
});

我已经尝试过此代码,但无法正常工作。

1 个答案:

答案 0 :(得分:1)

s=df.index[df.A.eq(0)] pd.Series(np.arange(len(s))+1,index=s).reindex(df.index,method='bfill') Out[41]: 0 1 1 1 2 1 3 2 4 2 5 2 dtype: int32 函数返回一个没有.text()方法的字符串。您要在元素本身上运行该方法,不需要首先调用fadeOut()

.text()
$("#button_fade").on("click", function() {
  if ($(this).text() == "HELLO") {
    $(this).fadeOut(function() {
      $(this).text("WORLD").fadeIn();
    });
  }
});

如果您要淡化文本而不是淡化整个按钮,则需要在按钮内放置一个元素并对其执行淡入淡出效果。

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="button_fade">HELLO</button>
$("#button_fade").on("click", function() {
  if ($(this).text() == "HELLO") {
    $(this).children("span").fadeOut(function() {
      $(this).text("WORLD").fadeIn();
    });
  }
});

相关问题