您的位置:首页 > Web前端 > JavaScript

Knockout.js hasFocus

2015-08-17 16:50 537 查看
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/knockout-3.3.0.js"></script>
<script type="text/javascript">

function PersonViewModel(name) {
// Data
this.name = ko.observable(name);
this.editing = ko.observable(false);

// Behaviors
this.edit = function () { this.editing(true) }
}

$(function () {
ko.applyBindings(new PersonViewModel("Bert Bertington"));
})
</script>
</head>
<body>
<p>
Name:
<b data-bind="visible: !editing(), text: name, click: edit"> </b>
<input data-bind="visible: editing, value: name, hasFocus: editing" />
</p>
<p><em>Click the name to edit it; click elsewhere to apply changes.</em></p>
</body>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: