1 /** 2 * 表单中的默认字符,点击后隐藏这些字符 3 * @constructor 4 * @author putaoshu@126.com 5 * @param {Object} obj 主对象 6 * @date 2012-02-08 7 * @example <input type="text" defaultchars="搜索大家共享的文件"> 8 */ 9 10 vui.defaultchars = function(obj){ 11 var $this = $(obj); 12 if($this.val()) return; 13 var $defaultchars = $this.attr('defaultchars'); 14 $this.val($defaultchars); 15 $this.focusin(function(){ 16 if ($this.val() == $defaultchars) $this.val(''); 17 }).focusout(function(){ 18 if ($this.val() == '') $this.val($defaultchars); 19 }); 20 }