今天分享下同事关于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>
求大佬看完后分析下,或等我改天询问到再分享给大伙。