【发布时间】:2017-12-31 05:28:46
【问题描述】:
我有 3 个按钮,单击时应将不同的容器添加到外部的空 div 中
<button id="a" data-bind="clickme" value="1">a</button>
<div id="empty1">
<button id="b" data-bind="clickme" value="2">b</button>
<div id="empty2">
<button id="c" data-bind="clickme" value="3">c</button>
<div id="empty3">
<!-- the container below should replace the empty div -->
<div class="container" id="big_container" data-bind="visible : openContainer">
<p> Hello world !</p>
</div>
所有按钮都可以通过一个淘汰赛js数据绑定点击我并具有值和id。
我想做的是让我们说按钮 a 被点击,它应该在 empty1 上显示容器,如果按钮 2 被点击,它应该在 empty2 上显示大容器。该容器被数据绑定隐藏,因此仅在单击按钮时才会显示。
这是我正在使用的淘汰js函数
self.openContainer = ko.observable(false);
self.clickme= function(value){
if(value == 1){
// make the observable visible so the container should display
self.openContainer(true);
$("#empty1").load("big_container");
}
}
我正在尝试不工作的 jquery,并且我尝试了淘汰 js 组件注册,但我不确定它是如何工作的。
【问题讨论】:
标签: javascript jquery html knockout.js