如何从视图验证表单到模型?使用Backbone验证表格
我只想检查电子邮件和密码是否至少包含6个字符。如果为true,那么启用该按钮,如果没有,则抛出一条消息。
HTML
<form>
<input type="text" name="email" placeholder="Type your email here." />
<input type="password" name="password" placeholder="Type your password here." />
<button disabled>Log In</button>
</form>
的JavaScript
var User = new Backbone.Model.extend({
});
var AppView = Backbone.View.extend({
el: $('form'),
events: {
'keyup input[name=email]': 'validationScope'
},
initialize: function() {
this.render();
},
validationScope: function() {
console.log('testing');
// What to do here?
}
});
var appView = new AppView();
要播放,做到这一点right here。
幽秘ght想要考虑做一些形式的骨干和验证教程;这是一个相当广泛的问题,有很多不同的答案。 –