兼容IE8 input的placeholder的文字显示

if( !('placeholder' in document.createElement('input')) ){          
    $('input[placeholder],textarea[placeholder]').each(function(){              
        var that = $(this),               
        text= that.attr('placeholder');               
        // console.log(text);            
        if(that.val()===""){                   
            that.val(text).addClass('placeholder');               
        }               
        that.focus(function(){                   
            if(that.val()===text){                     
                that.val("").removeClass('placeholder');                   
            }               
        }).blur(function(){                
            if(that.val()===""){                    
                that.val(text).addClass('placeholder');                   
            }               
        }).closest('form').submit(function(){                   
            if(that.val() === text){                     
            that.val('');                   
            }               
        });               
    });       
}

 

posted @ 2016-12-25 20:23  以茜为贵  阅读(1548)  评论(0编辑  收藏  举报