gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 17:17:44 25 4
gpt4 key购买 nike

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

我遇到的情况是,当用户单击提交按钮时,即使页面文本框仍然有必填字段, Bootstrap 也会加载。

这是我当前的代码

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

请帮忙

最佳答案

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

试试这个: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();
});
}
});
});

关于javascript - 如何在文本仍为空时关闭引导加载按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24263980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com