我创建了一个登录模型,
define(["knockout", "text!./login.html"], function (ko, loginTemplate) {
function loginViewModel() {
var self = this;
self.email = ko.observable("");
self.pass = ko.observable();
self.newEmail = "";
self.newPass = "";
self.email.subscribe(function(newValue) {
self.newEmail = newValue;
});
self.pass.subscribe(function(newValue) {
self.newPass = newValue;
});
self.login = function(){
alert(self.newEmail);
alert(self.newPass);
}
return self;
}
return { viewModel:loginViewModel, template: loginTemplate };
});
我想获得电子邮件和密码输入的价值。上面的代码工作,但我使用.subscribe函数。有没有其他方法来获得电子邮件和密码的价值?