0
我被困在一个简单的代码,它使type
即a
仅在类型为a
时才可见。我已经使用了KnockoutJS
。我尝试了很多,但我无法找出错误。KnockoutJS可见绑定不起作用
HTML:
<a href="#" data-bind="click: changeType('b')">change the type</a>
<span data-bind="visible: isType('a')">a</span>
JS:
function viewModel = {
var self = this;
self.type = ko.observable();
self.isType = function(type) {
return type == self.type();
};
self.changeType = function(para){
return function(){
self.type(para);
}
};
}
ko.applyBindings(new viewModel());
JSFiddle为上述代码。