2012-01-27 44 views
2

我正在使用此腳本:http://www.morethannothing.co.uk/wp-content/uploads/2010/01/placeholder.js可以在IE中獲得一些佔位符。適用於輸入類型的文本和密碼。IE中的佔位符

但只是似乎不加載文本區域。有沒有人知道我可以加入的一行代碼,或者可能需要一點點jQuery或JavaScript來執行才能加載它。

在此先感謝。

+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) – 2012-01-27 10:14:06

+0

同意。佔位符插件是一個偉大的發現,非常有用。 – StuBlackett 2012-01-27 10:17:44

回答

1

代替$(':text[placeholder],:password[placeholder]')使用$(':text[placeholder],:password[placeholder],textarea[placeholder]')

+1

你不應該使用':text',':password'或其他任何jQuery組成的選擇器(如果你可以提供幫助的話),因爲不用瀏覽器的* fast *,本地選擇器引擎,Sizzle必須完成所有的工作本身通過遍歷 - 在這種情況下 - DOM中的所有元素。 – 2012-01-27 10:09:58

0

對於所有輸入和文本區域: $( '輸入[佔位符],文本區域[佔位符')

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>