Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 根据Knockout.js中选择列表的选定选项显示或隐藏HTML元素?_Javascript_Html_Knockout.js - Fatal编程技术网

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);
}