如何将焦点设置在durandal单页面应用程序中的特定元素上?
答案 0 :(得分:0)
You should be able to use addBindingHandler for this specific purpose.
举个例子:
ko.bindingHandlers.hasFocus = {
init: function(element, valueAccessor) {
$(element).focus(function() {
var value = valueAccessor();
value(true);
});
$(element).blur(function() {
var value = valueAccessor();
value(false);
});
},
update: function(element, valueAccessor) {
var value = valueAccessor();
if (ko.unwrap(value))
element.focus();
else
element.blur();
}
};