Placeholder attribute on input tags for IE?

前端 未结 6 905
你的背包
你的背包 2021-01-04 03:30

I know that Internet Explorer doesn\'t support the placeholder attribute for input tags, but surely in 2012 there must be another solution for IE?

相关标签:
6条回答
  • 2021-01-04 04:11

    I wrote a jQuery plugin a while back that will add placeholder support to any browser that does not support it.

    Placeholder Text in IE

    0 讨论(0)
  • 2021-01-04 04:16

    Yes, there is a quite easy solution for IE8 and IE9 because on grater versions of IE it already works. (IE10, IE11, etc)

    This is the solution i found:

    1. Detect Internet Explorer version

    <!--[if lt IE 10]>       
        <script type="text/javascript">var ie = 9;</script>      
    <![endif]-->     
    <!--[if lt IE 9]>                   
        <script type="text/javascript">var ie = 8;</script>          
    <![endif]-->  
    

    2. Fix the placeholder

    if (typeof ie == 'undefined') var ie = 10;   
    if (ie == 8 || ie == 9){  
    
        $("input[placeholder]").each(function() {
            this.value = $(this).attr('placeholder');
        });        
    
        $("input[placeholder]").focus(function() 
            if (this.value == $(this).attr('placeholder')) this.value = '';
        }).blur(function() {   
            if (this.value == '')
                this.value = $(this).attr('placeholder'); 
        });
    }
    
    0 讨论(0)
  • 2021-01-04 04:24

    Actually, IE does support the placeholder attribute in 2012 (Version 10). Couple this with a polyfill for older browsers, and you should have a well-rounded solution to your problem.

    0 讨论(0)
  • 2021-01-04 04:25

    http://the.deerchao.net/PlaceHolder it works on ie without call any function...

    0 讨论(0)
  • 2021-01-04 04:26

    Try this jQuery plugin developed by me

    https://github.com/ramsunvtech/jQuery-Plugins/tree/master/IEPlaceHolder

    0 讨论(0)
  • 2021-01-04 04:35

    We've been using this jQuery plugin in production for a few weeks now and it seems to be working great.

    http://webcloud.se/code/jQuery-Placeholder/

    0 讨论(0)
提交回复
热议问题