knockoutjs:Example 1: checked=checkedにする:The checked binding

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>knockoutjs:Example 1: checked=checkedにする:The checked binding</title>
  6. <script type="text/javascript" src="knockout-2.1.0beta.js"></script>
  7. </head>
  8. <body>
  9. <h1>knockoutjs:Example 1: checked=checkedにする:The checked binding</h1>
  10. <p>Send me spam: <input type="checkbox" data-bind="checked: wantsSpam" /></p>
  11. <script type="text/javascript">
  12.   var viewModel = {
  13.     wantsSpam: ko.observable(true) // Initially checked
  14.   };
  15.   // ▼ checked=checkedにしない場合
  16.   // viewModel.wantsSpam(false); // The checkbox becomes unchecked
  17.   ko.applyBindings(viewModel);
  18. </script>
  19. <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
  20. <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
  21. <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
  22. </div>
  23. <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
  24. Copyright &copy; 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
  25. </div>
  26. </body>
  27. </html>