当前位置 : 主页 > 网络编程 > JavaScript >

为IE9定做的placeholder兼容样式

来源:互联网 收集:自由互联 发布时间:2021-06-30
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
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)
网友评论