Show “loading” animation on button click

前端 未结 6 1075
感情败类
感情败类 2021-01-30 14:10

I want to do something very simple. I have one button in my page.

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-30 14:41

    try

    $("#btnId").click(function(e){
     e.preventDefault();
     //show loading gif
    
     $.ajax({
      ...
      success:function(data){
       //remove gif
      },
      error:function(){//remove gif}
    
     });
    });
    

    EDIT: after reading the comments

    in case you decide against ajax

    $("#btnId").click(function(e){
         e.preventDefault();
         //show loading gif
         $(this).closest('form').submit();
    });
    

提交回复
热议问题