knockoutjs:Example 1: 条件によってCSS指定:The css binding
- <!DOCTYPE html>
- <html lang="ja">
- <head>
- <meta charset="UTF-8">
- <title>knockoutjs:Example 1: 条件によってCSS指定:The css binding</title>
- <script type="text/javascript" src="knockout-2.1.0beta.js"></script>
- <style type="text/css">
- .profitWarning{
- color:red;
- }
- </style>
- </head>
- <body>
- <h1>knockoutjs:Example 1: 条件によってCSS指定:The css binding</h1>
- <div data-bind="css: { profitWarning: currentProfit() < 0 }">
- Profit Information
- </div>
- <script type="text/javascript">
- var viewModel = {
- currentProfit: ko.observable(150000) // Positive value, so initially we don't apply the "profitWarning" class
- };
- viewModel.currentProfit(-50); // Causes the "profitWarning" class to be applied
- ko.applyBindings(viewModel);
- </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>