<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Demo2-双向绑定</title>
<script type='text/javascript' src='knockout-3.5.1.js'></script>
</head>
<body>
<!--双向绑定-->
<div>
</div>
<div data-bind="visible: shouldShowMessage">
<h1>我来也</h1>
</div>
<input type="button" value="Show" onclick="show()">
<input type="button" value="Hide" onclick="hide()">
<script type="text/javascript">
var AppViewModel = {
shouldShowMessage: ko.observable(true)
};
function show(){
AppViewModel.shouldShowMessage(true);
}
function hide(){
AppViewModel.shouldShowMessage(false);
}
ko.applyBindings( AppViewModel);
</script>
</body>
</html>