简体   繁体   English

文本仍然为空时如何关闭Bootstrap加载按钮

[英]How to off the Bootstrap Loading Button while text is still Empty

Please help I want to off the bootstrap loading button while my textbox is still empty the user need to fill all textbox before the submit button will change the text to loading 请帮助我在我的文本框仍然为空的情况下关闭引导加载按钮,用户需要在提交按钮将文本更改为加载之前填充所有文本框

whats happening to me is that when the user click the submit button the bootstrap is loading too even the page textbox still has a required field. 我发生的事情是,当用户单击“提交”按钮时,引导程序也正在加载,即使页面文本框仍具有必填字段。

this my current code 这是我当前的代码

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css">
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script type="text/javascript">  
$(function() { 
$(".btn").click(function(){
    $(this).button('loading').delay(1000).queue(function() {
        $(this).button('reset');
        $(this).dequeue();
    });        
});
});   
</script>

<form class="form-horizontal" action="button.php" method="post" style=" width:450px;">

    <label class="control-label col-xs-3">Username Name :</label>
    <input type="textbox" class="form-control" name="txtfirst" placeholder="First Name"required>

    <label class="control-label col-xs-3">Password :</label>
    <input type="textbox" class="form-control" name="txtlast" placeholder="Last Name"required>

    <button type="submit" class="btn btn-primary" data-loading-text="    Loading...    ">Login</button>
</form>

Please help 请帮忙

From the code it looks like your js function call is bound to click event of the button and not submit event of the form. 从代码看来,您的js函数调用绑定到按钮的click事件,而不是表单的Submit事件。 The click event does not do any form validations. click事件不执行任何表单验证。

Try this: http://jsfiddle.net/Dde4U/ 试试这个: http : //jsfiddle.net/Dde4U/

$(function() { 
    $(".btn").click(function(){
        if($('.form-horizontal').valid()){ //Checks if form is valid
            $(this).button('loading').delay(1000).queue(function() {
                $(this).button('reset');
                $(this).dequeue();
            });      
        }
    });
}); 

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

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