플러그인은 그 안에이 작업을 수행 :
$(this).addClass("disabled");
을이 자리 표시 자 텍스트를 사용하는 경우. 그래서, 당신은 당신의 CSS에서 같은 것을 넣어 할 수 있어야한다 :
input {
font-size: 13px;
color: #000;
}
input.disabled {
font-size: 12px;
color: #666;
}
그런 글꼴 크기가 이상한 시각 효과가 발생할 수 있습니다 변경하지만 당신은 명시 적으로 높이를 사용하여 이러한 일을 방지 할 수 있습니다. 당신은 아마도 색상을 변경하고 폰트 크기를 IMHO로 일정하게 유지하는 것이 나을 것입니다.
동일한 작업을 수행 할 수도 있습니다.이 작업은 placeholder
대신 title
속성을 사용하고 포함 된 양식이 제출되면 자리 표시 자 텍스트도 지 웁니다.
(function($) {
$.fn.egText = function(options) {
options = $.extend({ }, $.fn.egText.defaults, options || { });
var $all = this;
$all.focus(function() {
var $this = $(this);
if(!$this.data(options.dataKey))
$this.data(options.dataKey, 'yes').removeClass(options.egClass).val('');
})
.blur(function() {
var $this = $(this);
if($this.val() == '')
$this.addClass(options.egClass).removeData(options.dataKey).val($this.attr('title'));
else
$this.data(options.dataKey, 'yes');
})
.blur();
$.unique($all.closest('form')).submit(function() {
$all.each(function() {
var $this = $(this);
if(!$this.data(options.dataKey))
$this.val('');
});
return true;
});
};
$.fn.egText.defaults = {
dataKey: 'egText', // The key we use for storing our state with .data(), just in case there are conflicts...
egClass: 'lolite' // The CSS class to add to the <input> when we're displaying the example text.
};
})(jQuery);
감사 :
여기 내 코드에 대한 좀 더 많은 정보 쓴 위의 코드와도 기사에 대한 내 working ghost text example입니다. 도움이되었습니다. :) – ptamzz