/*******************************
 * @author fengyan
 * @author blog http://eflylab.cnblogs.com/
 * @2010.11.16
 * @可自由转载及使用,但请注明版权归属
 *******************************/
;(function($){
    $.fn.extend({
        iClear: function(options){
            var iset = {
                name: null,//获取表单元素比如$(':text')
                curVal: null,//默认显示文字,优先于表单默认值,为空时调用表单默认值
                color: '#000',//点击后输入值颜色
                curColor: '#ccc',//默认颜色
                enter: null
            }
            options = options || {};
            $.extend(iset, options);
            
            iset.name.each(function(){
                //当设置默认值是为表单赋默认值
                if (iset.curVal != null) {
                    iset.name.val(iset.curVal);
                }
                //表单focus,blur事件
                $(this).css('color', iset.curColor).focus(function(){
					$(this).css('color',iset.color);
                    if ($(this).val() == (iset.curVal ? iset.curVal : this.defaultValue)) {
                        $(this).val('');
                    }
                }).blur(function(){
                    if ($(this).val() == '') {
                        $(this).val(iset.curVal ? iset.curVal : this.defaultValue).css('color', iset.curColor);
                    }
                });
                //绑定回车事件
                if (iset.enter != null) {
                    $(this).keydown(function(e){
                        if (e.keyCode == 13) {
                            iset.enter.click();
                        }
                    });
                }
            });
        }
    });
})(jQuery);
