2012-01-27 6 views
2

私はこのスクリプトを使用しています:http://www.morethannothing.co.uk/wp-content/uploads/2010/01/placeholder.js IEにいくつかのプレースホルダを取得します。テキストとパスワードの入力タイプの処理を行います。IEのプレースホルダ

しかし、テキストエリアには読み込まれないようです。誰かがそれに追加できるコード行を知っていますか、それをロードするためにjQueryやJavaScriptを少し動かしてしまいます。

ありがとうございます。代わりに、すべての入力とテキストエリアについて$(':text[placeholder],:password[placeholder]')使用$(':text[placeholder],:password[placeholder],textarea[placeholder]')

+2

jQueryのプレースホルダプラグインがダースダイムであります'textarea'を直接サポートするものに切り替えることができます。これらはすべて[place5](http://code.google.com/p/place5/)(鉱山)、[jquery-placeholder](https://github.com/mathiasbynens/jquery-placeholder)、[jquery -placeholder(2)](https://github.com/danielstocks/jQuery-Placeholder) –

+0

合意しました。プレースホルダプラグインは素晴らしい発見と非常に便利でした。 – StuBlackett

答えて

1

: $( '入力[プレースホルダ]、TEXTAREA [プレースホルダ]')

+1

ブラウザーの*高速*ネイティブセレクターエンジンを使用するのではなく、シズルがすべてを実行しなければならないため、 ':text'、':password'、または他のjQueryのセレクターを使用しないでください。この場合、DOM内のすべての要素を反復処理することによって、ワーク自体 –

0
<script type="text/javascript"> 
    if(navigator.userAgent.indexOf("MSIE") > 0) 
    { 
     $(function() 
     { 
      var input = document.createElement("input"); 
      if(('placeholder' in input) == false) 
      { 
       $('[placeholder]').focus(function() 
       { 
        var i = $(this); 
        if(i.val() == i.attr('placeholder')) 
        { 
         i.val('').removeClass('placeholder'); 
         if(i.hasClass('password')) 
         { 
          i.removeClass('password'); this.type='password'; 
         } 
        } 
       }).blur(function() 
       { 
        var i = $(this); 
        if(i.val() == '' || i.val() == i.attr('placeholder')) 
        { 
         if(this.type=='password') 
         { 
          i.addClass('password'); this.type='text'; 
         } 
         i.addClass('placeholder').val(i.attr('placeholder')); 
        } 
       }).blur().parents('form').submit(function() 
       { 
        $(this).find('[placeholder]').each(function() 
        { 
         var i = $(this); 
         if(i.val() == i.attr('placeholder')) i.val(''); 
        }); 
       }); 
      } 
     }); 
    } 


    </script> 
関連する問題