我在这里有登录表单,
<form action="proseslogin.php" method="POST">
<input name="username" type="text" placeholder="username">
<input name="password" type="password" placeholder="password">
<button class="btn btn-info btn-block login" type="submit">Login</button>
</form>
js code
$(function(){
var textfield = $("input[name=username]");
$('button[type="submit"]').click(function(e) {
e.preventDefault();
//little validation just to check username
if (textfield.val() != "") {
//$("body").scrollTo("#output");
$("#output").addClass("alert alert-success animated fadeInUp").html("Welcome back " + "<span style='text-transform:uppercase'>" + textfield.val() + "</span>");
$("#output").removeClass(' alert-danger');
$("input").css({
"height":"0",
"padding":"0",
"margin":"0",
"opacity":"0"
});
//change button text
$('button[type="submit"]').html("continue")
.removeClass("btn-info")
.addClass("btn-default")
.click(function(){
$("input").css({
"height":"auto",
"padding":"10px",
"opacity":"1"
}).val("");
});
//show avatar
$(".avatar").css({
"background-image": "url(assets/img/clublogo.png)"
});
} else {
//remove success mesage replaced with error message
$("#output").removeClass(' alert alert-success');
$("#output").addClass("alert alert-danger animated fadeInUp").html("sorry enter a username ");
}
//console.log(textfield.val());
});
});
表格没问题且工作正常,但是当我在javascript中添加一些函数来制作漂亮的表单时,按钮从不执行操作并发布数据而是执行循环更改文本按钮功能
答案 0 :(得分:1)
因此,只有当button.html ==&#39;登录&#39; 。如果要检查,只需添加添加。
if ($(this).html() == 'Login') {
之后
$('button[type="submit"]').click(function(e) {
if ($(this).html() == 'Login') {
// all you code here
}
});