(function ($) {
$.fn.__Placeholder = function (options) {
this.el = $(this);
this.options = options;
this.fade_i = 0;
this.defualtsArray = ['fancy-hummingbird','amusing-meerkat','efficient-manatee','complete-otter','delicious-goat','mammoth-toad','mellow-spider','profuse-hummingbird','near-otter','delicious-eagle'];
//初始化方法
this._init = function(){
this._start();
}
this._start = function (){
var _this = this;
_this._placeholder = _this.el.attr('placeholder');
if(!_this._placeholder){
_this._placeholder = _this.defualtsArray[this._getRandom(_this.defualtsArray.length-1)];
_this._showPlaceholder(_this._placeholder);
}else{
_this._placeholder = _this.defualtsArray[_this._getRandom(_this.defualtsArray.length-1)];
setTimeout(function (){
_this._showPlaceholder(_this._placeholder);
},5000);
}
}
this._showPlaceholder = function (_content){
var _this = this,
contentLength = _content.length;
if(_this.fade_i < contentLength){
_this.el.attr('placeholder',_content.substring(0,_this.fade_i));
_this.fade_i = _this.fade_i + 1;
setTimeout(function (){
_this._showPlaceholder(_content);
},35);
}else{
_this.fade_i = 0;
_this._start();
}
}
this._getRandom = function (n){
return Math.floor(Math.random()*n+1);
}
this.el.on('input', function(){
//輸入
});
this.getValue = function(){
var value = this.el.val();
if(value == ''){
value = this.el.attr('placeholder');
}
console.log(value);
}
this._init();
return this;
};
})(jQuery); dom