gpt4 book ai didi

javascript - Backbone JS 事件未触发

转载 作者:行者123 更新时间:2023-12-02 18:20:38 24 4
gpt4 key购买 nike

我在使主干事件正常运行时遇到问题。我只是想模拟表单提交并获得警报,但我似乎无法到达那里......

我的标记如下:

<form method="post" id="userSignIn">       
<label>Email</label>
<input type = "text" name = "useremail" value = "" id="userEmail">

<br />

<label>Pass</label>
<input type = "password" name = "userpass" value = "" id="userPassword">

<br /><input type = "submit" value = "Submit">
</form>

我的JS

var events = _.clone(Backbone.Events);

var SigninModel = Backbone.Model.extend({
url: 'http://localhost/api/app/User.php',
});

var SignInCollection = Backbone.Collection.extend({
model: SigninModel
})

var SigninView = Backbone.View.extend({
events: {
'submit #userSignIn': 'signIn'
},

initialize: function() {
console.log('Sign in view initialized');
},

signIn: function(e) {
alert("Your username is" + $('#userSignIn #userEmail'));
e.preventDefault();
}
});

$(document).ready(function(){
var signInCollection = new SignInCollection();
new SigninView({ el: $('#userSignIn'), collection: signInCollection });
});

最佳答案

Backbone.View.events 只会查找由属于 View 元素(或该元素的子元素)的 DOM 元素触发的事件。理想情况下,您可以通过 View 上的 render 方法渲染此 HTML,但另一种方法是从 SignInView.initialize 内部调用 setElement

关于javascript - Backbone JS 事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18863946/

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