首页 > 代码库 > 判断浏览器是否支持某些新属性---placeholder兼容问题解决

判断浏览器是否支持某些新属性---placeholder兼容问题解决

function is_true(){
    return ‘placeholder‘ in document.createElement(‘input‘);
}

实例:placeholder在低版本IE浏览器下兼容性解决

<script type="text/javascript"> 
if( !(‘placeholder‘ in document.createElement(‘input‘))){  
    $(‘input[placeholder],textarea[placeholder]‘).each(function(){   
          var that = $(this),
          text= that.attr(‘placeholder‘);   
          if(that.val()===""){   
            that.val(text);   
          }
          that.focus(function(){   
            if(that.val()===text){   
                  that.val("");   
            }   
          }).blur(function(){   
            if(that.val()===""){   
                  that.val(text);   
            }
          }).closest(‘form‘).submit(function(){   
            if(that.val() === text){
                  that.val(‘‘);   
            }
          });
    });
}
</script> 

 

判断浏览器是否支持某些新属性---placeholder兼容问题解决