Javascript 如何在文本仍然为空时关闭引导加载按钮

Javascript 如何在文本仍然为空时关闭引导加载按钮,javascript,jquery,html,twitter-bootstrap-3,Javascript,Jquery,Html,Twitter Bootstrap 3,请帮忙 我想在文本框仍然为空时关闭引导加载按钮 用户需要填写所有文本框,然后submit按钮将文本更改为loading 发生在我身上的是,当用户单击提交按钮时,引导程序也在加载,即使页面文本框仍然有一个必填字段 这是我当前的代码 <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"> <link rel="stylesheet" hre

请帮忙 我想在文本框仍然为空时关闭引导加载按钮 用户需要填写所有文本框,然后submit按钮将文本更改为loading

发生在我身上的是,当用户单击提交按钮时,引导程序也在加载,即使页面文本框仍然有一个必填字段

这是我当前的代码

<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>

$(函数(){
$(“.btn”)。单击(函数(){
$(this).button('loading').delay(1000).queue(function(){
$(此).button('reset');
$(this.dequeue();
});        
});
});   
用户名:
密码:
登录

请帮助

从代码上看,您的js函数调用似乎绑定到单击按钮的事件,而不是表单的提交事件。单击事件不执行任何表单验证

试试这个:


我应用了你的代码并填写了文本框。页面正在提交,但我需要的是在页面提交或加载时将“登录”更改为“加载”。单击和提交之间的时间可以忽略不计。我将其应用于简历表单中的其他表单数据输入。因为保存简历中的所有信息需要时间,所以我想在按钮中添加加载。我只是创建用户名和密码作为示例。
$(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();
            });      
        }
    });
});