如何实现针对IE9的定制placeholder样式兼容性?

更新于
2026-09-29 11:33:35
1阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计121个文字,预计阅读时间需要1分钟。

如何实现针对IE9的定制placeholder样式兼容性?

jQuery.placeholder.jsjavascript(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; var placeholderValue=opts.placeholder; // 代码省略 }); };})();

jquery.placeholder.js

(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"), typeValue = _this.getAttribute("type") if (isIE) { _this.setAttribute("type", "text") _this.setAttribute("value", placeholderValue) _this.onfocus = function() { if(typeValue == "password") _this.setAttribute("type", typeValue) if($.trim(_this.value) == placeholderValue) _this.value = "" } _this.onblur = function() { if($.trim(_this.value) == "") { _this.value = placeholderValue if(typeValue == "password") _this.setAttribute("type", "text") } } } }) } })(jQuery)

如何实现针对IE9的定制placeholder样式兼容性?

本文共计121个文字,预计阅读时间需要1分钟。

如何实现针对IE9的定制placeholder样式兼容性?

jQuery.placeholder.jsjavascript(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; var placeholderValue=opts.placeholder; // 代码省略 }); };})();

jquery.placeholder.js

(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"), typeValue = _this.getAttribute("type") if (isIE) { _this.setAttribute("type", "text") _this.setAttribute("value", placeholderValue) _this.onfocus = function() { if(typeValue == "password") _this.setAttribute("type", typeValue) if($.trim(_this.value) == placeholderValue) _this.value = "" } _this.onblur = function() { if($.trim(_this.value) == "") { _this.value = placeholderValue if(typeValue == "password") _this.setAttribute("type", "text") } } } }) } })(jQuery)

如何实现针对IE9的定制placeholder样式兼容性?