【发布时间】:2011-08-27 12:29:11
【问题描述】:
我正在尝试制作一个 jquery 插件(只是为了好玩),但我似乎无法在某个部分做我想做的事。
(function($){
var resetText = function(){ if (this.value == "") this.value = this.title; }
var clearText = function(){ if (this.value == this.title) this.value = ""; }
$.fn.placeHolder = function() {
return this.each(function(){
resetText(); // <-- this doesn't work
$(this).focus(clearText).blur(resetText);
});
};
})(jQuery);
基本上,我希望将 title 属性复制到 doc.ready 和 field.blur 上的 value 属性(如果值为空)
就像现在一样,它适用于Blur,但不适用于 document.ready
我觉得这是一个范围问题,但老实说我不知道如何解决它。
【问题讨论】:
标签: jquery plugins jquery-plugins scope