<input type="text" id="txtFirstname" data-bind="value:firstName,valueUpdate:'afterkeydown'" />
<i data-bind="css:RequiredStyle(firstName)"></i>
var ViewModel = function () {
var self = this;
self.firstName = ko.observable("Hello World!");
self.RequiredFieldStyle=function (controlValue) {
alert('called');
var hasValue = controlValue().length;
if (hasValue > 0) {
return "fa fa-check-circle";
} else {
return "fa fa-exclamation-circle";
}
};
};
如何为RequiredFieldStyle
in 中的函数创建实用方法knockout.js
?