【发布时间】:2017-04-19 11:24:35
【问题描述】:
我被困在一个简单的代码上,它是使 type 即 a 仅在其类型为 a 时才可见。我也用过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 以上代码。
【问题讨论】:
标签: javascript html knockout.js