Unobtrusive JavaScript - HTMLの中にJavaScriptを書かないようにするスタイル http://www.ark-web.jp/sandbox/wiki/222.html
Unobtrusive JavaScript - HTMLの中にJavaScriptを書かないようにするスタイル
- 最近
Ajaxデザインパターン ―ユーザビリティと開発効率の向上のために (大型本)
http://www.amazon.co.jp/dp/4873113237
という本を読んでいます。 - その本の中に「Unobtrusive JavaScript」という言葉が出てきたので調べてみました。
- HTML内にJavaScriptをできるだけ書かないようにしようというコーディングスタイルを「Unobtrusive JavaScript」と呼ぶらしいです。
Unobtrusive JavaScript - Wikipedia †
- Unobtrusive JavaScript - Wikipedia
http://en.wikipedia.org/wiki/Unobtrusive_JavaScript
の超訳。Unobtrusive JavaScript can be seen as part of the larger Web standards movement;
「Unobtrusive JavaScript」は、大きなWeb標準の動きの一部としてみることができる。much as the demand for cross-browser compatibility has driven the increasing emphasis on standardized markup and style,
クロスブラウザに対するより多くの要求が、標準のマークアップとスタイルの標準化の強調の増加を推進しているthe increasing demand for rich Internet applications is driving the movement toward the more robust methods of unobtrusive JavaScript.
RIAの要求の増加は、Unobtrusive JavaScriptのより頑強な方法の方向への移動を推進している<input type="text" name="date" onchange="validateDate(this);" />
こんな風に、<input>タグのonchangeに書くのではなく、CSSでclassを割り振って、そこにイベントを動的に当て込め、と。<input type="text" name="date" class="datefield" />
// Register onchange event handlers for all datefield elements // This script uses objects and methods specific to the Prototype library datefields = document.getElementsByClassName("datefield"); datefields.each(function(e){ Event.observe( e, "change", validateDate ); });
たしかに! †
- そういう必要性はすごく感じますし、いたるところでも言われていますよね。
- ついこないだまで読んでいた
Ajaxインアクション
http://www.amazon.co.jp/dp/4844322222
では、HTML内にjavascriptを書くのは、初期のPHPプログラミングで、HTMLとPHPを混在させて書いていたのと似ている、というようなことが書いてました。 - やっぱり、こういった組み方を積極的にやって言った方がいいですよね。
- 同様に、Unobtrusive CSSという言葉もあると、この本に書いてありました。
tag: JavaScript