gpt4 book ai didi

javascript - JQuery HTML5 表单

转载 作者:行者123 更新时间:2023-11-28 13:33:00 26 4
gpt4 key购买 nike

我有一个简单的表格:

 <div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4" >
<form class="form-signin" role="form" id="login-form">
<h2 class="form-signin-heading">Please sign in</h2>
<input type="email" class="form-control" placeholder="Email address" required autofocus>
<input type="password" class="form-control" placeholder="Password" required>
<label class="checkbox">
<input type="checkbox" value="remember-me"> Remember me
</label>
<button class="btn btn-lg btn-primary btn-block" type="submit" id="login-but-sub">Sign in</button>
</form>
</div> <!-- form container -->
</div>
</div> <!-- /container -->

在 HTML 5 Web 应用程序中(如果存在差异,则为 ember JS),HTML 5 表单验证,如所述 here工作完美。我正在附加一个 JQuery 事件:

$(function(){
/*Try to restore user once upon loading*/
restore_user();
App = Ember.Application.create({
LOG_TRANSITIONS: true, });

client = new client()


App.Router.map(function() {
this.route('login');
});

App.IndexRoute = Ember.Route.extend({
setupController: function(controller) {
console.log(client);
if(!client.isLoggedIn()){
this.transitionTo('login')
}
}
});
$("#login-but-sub").submit(function(event){
console.log("login clicked");
});

});

问题是该事件似乎从未被触发......如果我将其更改为:

    $("body").submit(function(event){

    $("body").on('submit','body',function(event)

那么它也可以工作。第一个有什么问题?

最佳答案

<button> 上未触发提交事件它在 <form> 上触发。

在您的示例中,提交事件冒泡到 <body>

关于javascript - JQuery HTML5 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23474345/

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