inputタグ全てにイベントを付加する

[新着] Webテンプレートを仮オープンしました



0   名前: tentenmusi : 2006/10/11(水) 10:41  ID:nSEBVHdl
<input type="text" name="" onfocus="this.style.background='#FFFFCC'" onblur="this.style.background='#FFFFFF';">


このイベントハンドラをinputタグ全てに適用する方法を教えてください。
宜しくお願いします。

1   名前: NullPo : 2006/10/11(水) 10:41  ID:Z0FHbpib
こんなんでいいのかな。
もっと簡単な方法があるのかも。
<script type="text/javascript">
<!--

window.onload = function()
{
  var inputTags = document.getElementsByTagName("input");

  for( var ix = 0; ix < inputTags.length; ix++ ) {
    inputTags[ix].onfocus = function(){ this.style.background = '#FFFFCC'; };
    inputTags[ix].onblur = function(){ this.style.background = '#FFFFFF'; };
  }
}

// -->
</script>


2   名前: tentenmusi : 2006/10/11(水) 10:41  ID:nSEBVHdl
出来ました!
ありがとうございました!!

一覧へ戻る