这是一个相当标准的 UI 实践,所以我想我可以很快找到解决方案,但我没有运气。
这是我通常会为此功能编写的 jQuery:
(function($){
$.fn.focusClear = function(text) {
text = text || this[0].defaultValue;
this.focus(function() {
if($(this).val() == text) $(this).val('');
}).blur(function() {
if( $(this).val() == '') $(this).val(text);
});
return this;
};
})(jQuery);
如何使用 Angular 达到相同的效果?