focus blur textboxにメッセージを入れておく。 | javascript

input textboxの文字にメッセージを入れておく。


上が初期状態、下がフォーカス時。
(filterワードを入れるボックスなのでfilterと入れてあります。

<input type="text" value="filter" id="textbox_id" >

    $('#textbox_id').focus(function(){
      if( $('#textbox_id').val().match(/filter/)){
        $('#textbox_id').val('');
      }
      $('#textbox_id').css('color','#444444');
    });
    $('#textbox_id').blur(function(){
      if( $('#textbox_id').val() == ''){
        $('#textbox_id').val('filter');
        $('#textbox_id').css('color','#aaa');
      }
    });

focus時にfilterと入っていたら消して、blur時に空のときfilterと入れておく。

This entry was posted on 火曜日, 4月 10th, 2012 at 12:16 AM and is filed under Javascript. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Unityによるゲームを公開しております iOS/Android
https://itunes.apple.com/jp/app/lost-knight-3d-action/id900917032
https://play.google.com/store/apps/details?id=com.groundroad.runknight

各種開発支援・機能開発等小さいお仕事などもお請けしております。
unity開発支援, PHPシステム開発, javascript/html5 フロント開発, titanium mobileアプリ開発
お気軽にお問い合わせください
大崎・五反田近郊での対面でのお打ち合わせはいつでも可能です。