<input id="focusId" type="text" style="height: 40px;width: 80%;border: 1px solid #777e8c;">
<script>
//插件
;(function ($) {
$.fn.extend({
"placeholder":function(options){
var self=this;
options= $.extend({
defaultContent:"defaultContent",
defaultColor:"#777e8c",
inputColor:"#000"
},options);
this.val(options.defaultContent);
self.css("color",options.defaultColor);
this.focus(function(){
if(this.value==options.defaultContent){
self.val("");
self.css("color",options.inputColor);
}else{}
}).blur(function(){
if(!this.value){
self.val(options.defaultContent);
self.css("color",options.defaultColor);
}else{}
});
}
});
})(jQuery);
//调用
$("#focusId").placeholder({
defaultContent:"hello word",
defaultColor:"#c6c6c6",
inputColor:"#000"
});
</script>
自定义placeholder插件,实现设置input默认提示内容,颜色
原文:http://www.cnblogs.com/hcw136156133/p/5037763.html