jQuery 单击时如何使用 Bootstrap 按钮显示动画 gif

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18568792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:58:32  来源:igfitidea点击:

How to show animated gif using Bootstrap button when clicked

jquerytwitter-bootstrapbutton

提问by Thomas

i know how to show loading... text when user click on Bootstrap button. this way i do it

我知道如何在用户单击 Bootstrap 按钮时显示正在加载...文本。我这样做

http://jsfiddle.net/YCst4/1/

http://jsfiddle.net/YCst4/1/

add two dependency files
1) bootstrap.min.css 
2) bootstrap.min.js 

<button class="btn" id="button" data-text-loading="Loading...">Press Me</button>
$('#button').button();

$('#button').click(function() {
    $(this).button('loading');
});

now how could i show this animated gif http://www.bba-reman.com/images/fbloader.gifat the place of button when user will click on button.

现在我如何在用户单击按钮时在按钮位置显示此动画 gif http://www.bba-reman.com/images/fbloader.gif

please guide me how to do with sample code if possible. thanks

如果可能,请指导我如何处理示例代码。谢谢

回答by Alvaro

What about this:

那这个呢:

$('#button').button();

$('#button').click(function() {
    $(this).html('<img src="http://www.bba-reman.com/images/fbloader.gif" />');
});

Living demo: http://jsfiddle.net/YCst4/857/

现场演示:http: //jsfiddle.net/YCst4/857/

回答by Artyom Neustroev

If I understood you correctly, have a look at this Fiddle.

如果我理解正确,请看一下这个Fiddle

I used CSS backgroundattribute and jQuery .show()and .hide()methods:

我使用了 CSSbackground属性和 jQuery.show()和 . hide()方法:

$('#button').click(function () {
    $(this).hide();
    $(".loader").show();
});

回答by edotassi

$('#button').click(function() {
    $(this).replaceWith('<img src="[loader-url]" />');
});