Javascript 根据Knockout.js中选择列表的选定选项显示或隐藏HTML元素?
仅当从我的Javascript 根据Knockout.js中选择列表的选定选项显示或隐藏HTML元素?,javascript,html,knockout.js,Javascript,Html,Knockout.js,仅当从我的select列表中选择了第二个选项时,我才希望div可见/隐藏。这是我的代码,我正试图实现它的功能 HTML: 在FilterModel()函数中定义self.selectedChoice=ko.observable(),并在选择列表标记中指定value:selectedChoice以获取选择列表的选定值 <select data-bind="options: Datevalue , value: selectedChoice"> </select> fun
select
列表中选择了第二个选项时,我才希望div
可见/隐藏。这是我的代码,我正试图实现它的功能
HTML:
在FilterModel()函数中定义self.selectedChoice=ko.observable(),并在选择列表标记中指定value:selectedChoice以获取选择列表的选定值
<select data-bind="options: Datevalue , value: selectedChoice">
</select>
function FilterModel() {
var self = this;
self.selectedChoice = ko.observable();
self.Datevalue = ko.observableArray(['France', 'Germany', 'Spain']);
// boolean for showing the second select
this.showSecond = ko.computed(function () {
return this.selectedChoice() == this.Datevalue()[1];
}, this);
}
此.Datevalue
是一个数组。它永远不会有2ah的值,我想选择数组中的第二项而不是值,但没有规定“Germany”。我已经有一段时间没有使用ko了,所以我不知道怎么做了。对不起,我的荣幸:-)
<select data-bind="options: Datevalue , value: selectedChoice">
</select>
function FilterModel() {
var self = this;
self.selectedChoice = ko.observable();
self.Datevalue = ko.observableArray(['France', 'Germany', 'Spain']);
// boolean for showing the second select
this.showSecond = ko.computed(function () {
return this.selectedChoice() == this.Datevalue()[1];
}, this);
}