knockoutjs:font-weightやtext-decorationなど:The style binding

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>knockoutjs:font-weightやtext-decorationなど:The style binding</title>
  6. <script type="text/javascript" src="knockout-2.1.0beta.js"></script>
  7. <style type="text/css">
  8. .hoge{
  9.   color:red;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <h1>knockoutjs:font-weightやtext-decorationなど:The style binding</h1>
  15. <div data-bind="style: { fontWeight: currentProfit() < 0 ? 'bold' : 'normal' }">
  16.   「font-weight」を指定したければ「font-weight」ではなく「fontWeight」と記載。
  17. </div>
  18. <div data-bind="style: { textDecoration: currentProfit() < 0 ? 'underline' : 'line-through' }">
  19.   「text-decoration」を指定したければ「text-decoration」ではなく「textDecoration」と記載。
  20. </div>
  21. <p style="font-size:10pt;">※他にもいくつか記載を変更する必要あり。<a href="//www.comptechdoc.org/independent/web/cgi/javamanual/javastyle.html">一覧</a></p>
  22. <script type="text/javascript">
  23.   var viewModel = {
  24.     currentProfit: ko.observable(150000) // Positive value, so initially black
  25.   };
  26.   viewModel.currentProfit(-50); // Causes the DIV's contents to go red
  27.   ko.applyBindings(viewModel);
  28. </script>
  29. <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
  30. <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
  31. <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
  32. </div>
  33. <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
  34. Copyright &copy; 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
  35. </div>
  36. </body>
  37. </html>