createPlaceholder 函数

    function createPlaceholder(id,text,top,left){
        top = top || 0;
        left = left || 0;

        var obj = $('#' + id)[0],
            parent = obj.parentNode,
            clickEvent = function(){
                $(this).hide();
                var target = this.nextSibling;
                if( target.nodeName=='#text' )
                {
                    target = target.nextSibling;
                }
                target.focus();            
            },
            blurEvent = function(){
                var value = $.trim(this.value);
                if( value=='' )
                {
                    $(div).show();
                }
            },
            focusEvent = function(){
                $(div).hide();
            };
        var div = document.createElement('div');
        div.innerHTML = text;
        $(div).css({position: 'absolute', top: top, left: left, color: "red"});
        parent.insertBefore(div,obj);
        $(div).click(clickEvent);
        $(obj).blur(blurEvent);
        $(obj).focus(focusEvent);
    }

 

posted @ 2014-07-30 10:53  chy1000  阅读(265)  评论(0编辑  收藏  举报