1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | /** * 解决IE下不支持placeholder属性 * 可以根据自己的需要去扩展 * ps:写的很简单 根据自己的需求来 不喜勿喷 */ ; (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); |
使用很简单
1 | $("input").placeholder(); |
特别申明:
本站所有资源都是由网友投稿发布,或转载各大下载站,请自行检测软件的完整性!
本站所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!
如有侵权请联系我们删除下架,联系方式:lei1294551502@163.com