今天分享下同事关于input 属性placeholder 在IE9下不兼容的解决方案,小弟不是很懂,希望有看完的大佬说说你们的理解

<script src="http://www.jq22.com/jquery/1.8.3/jquery.min.js"></script>
<script>
(function($){
    $.fn.placeholder = function(options){
        var opts = $.extend({}, $.fn.placeholder.defaults, options);
        var isIE = document.all ? true : false;
        return this.each(function(){
            var _this = this,
                placeholderValue =_this.getAttribute("placeholder"); //缓存默认的placeholder值
            if(isIE){
                _this.setAttribute("value",placeholderValue);
                _this.onfocus = function(){
                    $.trim(_this.value) == placeholderValue ? _this.value = "" : '';
                };
                _this.onblur = function(){
                    $.trim(_this.value) == "" ? _this.value = placeholderValue : '';
                };
            }
        });
    };
})(jQuery);
$("input").placeholder();
</script>

求大佬看完后分析下,或等我改天询问到再分享给大伙。

相关文章:

  • 2019-08-16
  • 2021-06-01
  • 2021-10-23
  • 2021-05-22
  • 2022-12-23
  • 2021-05-30
  • 2021-12-17
猜你喜欢
  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2021-11-08
相关资源
相似解决方案