knockoutjs:Example 2: hasfocusの応用型:hasfocus binding
- <!DOCTYPE html>
- <html lang="ja">
- <head>
- <meta charset="UTF-8">
- <title>knockoutjs:Example 2: hasfocusの応用型:hasfocus binding</title>
- <script type="text/javascript" src="jquery-1.5.1.min.js"></script>
- <script type="text/javascript" src="knockout-2.1.0beta.js"></script>
- </head>
- <body>
- <h1>knockoutjs:Example 2: hasfocusの応用型:hasfocus binding</h1>
- <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>
- <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) }
- }
- ko.applyBindings(new PersonViewModel("Bert Bertington"));
- </script>
- <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
- <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
- <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
- </div>
- <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
- Copyright © 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
- </div>
- </body>
- </html>