简体   繁体   中英

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. The click event does not do any form validations.

Try this: 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();
            });      
        }
    });
}); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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