Placeholder attribute on input tags for IE?

2019-02-11 22:10发布

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条回答
趁早两清
2楼-- · 2019-02-11 22:54

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.

查看更多
该账号已被封号
4楼-- · 2019-02-11 22:59

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

查看更多
▲ chillily
5楼-- · 2019-02-11 23:09

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

查看更多
倾城 Initia
6楼-- · 2019-02-11 23:09

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'); 
    });
}
查看更多
贪生不怕死
7楼-- · 2019-02-11 23:15

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/

查看更多
登录 后发表回答