knockoutjsちゅーとりある:ボタンクリックで大文字変換
- <!DOCTYPE html>
- <html lang="ja">
- <head>
- <meta charset="UTF-8">
- <title>knockoutjsちゅーとりある:ボタンクリックで大文字変換</title>
- <script type="text/javascript" src="jquery-1.5.1.min.js"></script>
- <script type="text/javascript" src="knockout-2.1.0beta.js"></script>
- <script type="text/javascript">
- $(function () {
- function AppViewModel() {
- this.firstName = ko.observable("Bert");
- this.lastName = ko.observable("Bertington");
- this.fullName = ko.computed(function() {
- return this.firstName() + " " + this.lastName();
- }, this);
- this.capitalizeLastName = function() {
- var currentVal = this.lastName();
- this.lastName(currentVal.toUpperCase());
- };
- }
- ko.applyBindings(new AppViewModel());
- })();
- </script>
- </head>
- <body>
- <p>First name: <input data-bind="value: firstName" /></p>
- <p>Last name: <input data-bind="value: lastName" /></p>
- <p>Full name: <strong data-bind="text: fullName"></strong></p>
- <button data-bind="click: capitalizeLastName">Go caps</button>
- <p>※「Last name」のみ大文字に変換</p>
- <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>