jq 解決ie9-- 不支持iniput標籤屬性placeholder

;(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();
複製代碼
相關文章
相關標籤/搜索