-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-4visible.html
44 lines (30 loc) · 1.04 KB
/
1-4visible.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<input type="text" data-bind="visible:showValue"/>
<b>通过使用函数表达式来控制visible的显示隐藏</b>
<div data-bind="visible:DivShow().length>0">显示</div>
<span data-bind="text:userName"></span>
<div data-bind="html: details"></div>
</body>
<script type='text/javascript' src='js/knockout.js'></script>
<script>
var ViewModel = function() {
var self = this;
//隐藏元素
self.showValue = ko.observable(false);
//这里没内容,就隐藏div 数组中有内容,就显示
self.DivShow = ko.observableArray([]);
self.DivShow2 = ko.observableArray([1,2]);
self.userName = ko.observable({name:"12"});
self.details = ko.observable("<em>For further details, view the report <a href='report.html'>here</a>.</em>");
};
//实例化一个viewModel
var currentViewModel = new ViewModel();
ko.applyBindings(currentViewModel);
</script>
</html>