简体   繁体   English

将loading.gif图片添加到.val()

[英]adding a loading.gif image to .val()

How can I add a loading.gif image to .val() in my script? 如何在脚本中向.val()添加loading.gif图像?

I have tried: 我努力了:

this.submitButton.val('<input type="image" src="http://localhost:8000/loader.gif">').prop('disabled', true);

But it doesn't work! 但这不起作用! Any suggestions ? 有什么建议么 ?

   init: function() {
       this.form = $('#billing-form');
       this.submitButton = this.form.find('input[type=submit]');
       this.submitButtonValue = this.submitButton.val();

       var stripeKey = $('meta[name="publishable-key"]').attr('content');
       Stripe.setPublishableKey(stripeKey);

       this.bindEvents();
    },

    bindEvents: function() {
        this.form.on('submit', $.proxy(this.sendToken, this));
    },

    sendToken: function(event) {
        this.submitButton.val('<input type="image" src="http://localhost:8000/loader.gif">').prop('disabled', true);

        Stripe.createToken(this.form, $.proxy(this.stripeResponseHandler, this));

        event.preventDefault();
    },

Html is just a standard button like so: HTML只是像这样的标准按钮:

     <input type="submit" value="Subscribe"> 

this might be a solution to your problem: 这可能是您的问题的解决方案:

<button type="submit">Button</button>

$(document).ready(function(){
    $('button').on('click', function(){
       $(this).append('<img src="" width="10" height="10" />'); 
    });
});

notice that I have used button in my example, not input, as inputs do not allow to apply any content inside 请注意,我在示例中使用了按钮,而不是输入,因为输入不允许在其中应用任何内容

if you want to stick to the input markup, consider adding it some class when loading, eg. 如果您想坚持输入标记,请考虑在加载时将其添加到某个类,例如。

.loading {
    background: url(...)
}

here is a jsfiddle to first example: http://jsfiddle.net/Xu84a/ 这是第一个示例的jsfiddle: http : //jsfiddle.net/Xu84a/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM