/**
* 解决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();
|
以上是转载的,用来解决input的placeholder没有问题,
用在textarea就有问题,
所以我把代码拆开了写在自己的代码里就可以了,所以以上我认为可以参考,
提供思路,具体还得联系实际,举一反三。