模拟ie9的placeholder

ie9 的input框没有placeholder属性 啧啧啧~~~

所以就用span标签来模拟一下

先判断浏览器类型

if(navigator.useAgent.indexOf("MSIE 9.0")>0){
   啦啦啦,现在用的是ie9浏览器     
我想我家东东了~~~ }

封装函数

function ifie9(){
    //判断是否是ie9
    if(navigator.userAgent.indexOf("MSIE 9.0")>0){
        //input元素
        $(".ipt").each(function(){
            var self = $(this);
            self.parent().append('<span class="placeholder" data-type = "placeholder">我爱东东</span>')
            if(self.val() != ''){
                self.parent().find("span.placeholder").hide()
            }else{
                self.parent().find("span.placeholder").show()
            }
        }).on('foucs',function(){
            $(this).parent().find("span.placeholder").hide()
        }).on('blur',function(){
            var self = $(this);
            if(self.val != ''){
                self.parent().find("span.placeholder").hide()
            }else{
                self.parent().find("span.placeholder").show()
            }
        });
        $("span.placeholder").on('clock',function(){
            $(this).hide()
        })
    }
}
function ifie9(){
     //判断是否是ie9
     if( navigator. userAgent. indexOf( "MSIE 9.0")> 0){
         //input元素
         $( ".ipt"). each( function(){
             var self = $( this);
             self. parent(). append( '<span class="placeholder" data-type = "placeholder"></span>')
             if( self. val() != ''){
                 self. parent(). find( "span.placeholder"). hide()
            } else{
                 self. parent(). find( "span.placeholder"). show()
            }
        }). on( 'foucs', function(){
             $( this). parent(). find( "span.placeholder"). hide()
        }). on( 'blur', function(){
             var self = $( this);
             if( self. val != ''){
                 self. parent(). find( "span.placeholder"). hide()
            } else{
                 self. parent(). find( "span.placeholder"). show()
            }
        });
         $( "span.placeholder"). on( 'clock', function(){
             $( this). hide()
        })
    }
}

猜你喜欢

转载自www.cnblogs.com/wong-do/p/9047980.html