knockoutjs:Example 2: hasfocusの応用型:hasfocus binding

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>knockoutjs:Example 2: hasfocusの応用型:hasfocus binding</title>
  6. <script type="text/javascript" src="jquery-1.5.1.min.js"></script>
  7. <script type="text/javascript" src="knockout-2.1.0beta.js"></script>
  8. </head>
  9. <body>
  10. <h1>knockoutjs:Example 2: hasfocusの応用型:hasfocus binding</h1>
  11. <p>
  12.   Name:
  13.   <b data-bind="visible: !editing(), text: name, click: edit">&nbsp;</b>
  14.   <input data-bind="visible: editing, value: name, hasfocus: editing" />
  15. </p>
  16. <p><em>Click the name to edit it; click elsewhere to apply changes.</em></p>
  17. <script type="text/javascript">
  18.   function PersonViewModel(name) {
  19.     // Data
  20.     this.name = ko.observable(name);
  21.     this.editing = ko.observable(false);
  22.     // Behaviors
  23.     this.edit = function() { this.editing(true) }
  24.   }
  25.   ko.applyBindings(new PersonViewModel("Bert Bertington"));
  26. </script>
  27. <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
  28. <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
  29. <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
  30. </div>
  31. <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
  32. Copyright &copy; 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
  33. </div>
  34. </body>
  35. </html>