需要显示一段时间后自动消失
风格类似于EXCEL的注解
具体如何实现?

解决方案 »

  1.   

    title不行,不会自动显示出来
    alt没用过,不清楚
    需要在点击某button时,对input进行提示,提示信息出现在input旁边,过一会自动消失,期间最好不影响页面输入。
      

  2.   


    //引用js须放在body元素内或之下;调用示例<input type="text" id="txtName" onfocus="tips(this,200,'tips内容')" />
    //author:littlelam last modify:2008-04-21 15:11
    if (!document.body)
    alert("tips调用出错,引用js须放在body元素内或之下");
    if (!document.getElementById("tips"))
    {
    var element=document.createElement("div");
    element.id = "tips";
    element.style.cssText = "color:#000;position:absolute;z-index:999;font-size:12px;width:auto;";
    document.body.appendChild(element);
    }
    function getY(el)
    {
    var y=0;
    for(var e=el;e;e=e.offsetParent)y+=e.offsetTop;
    for(e=el.parentNode;e&&e!=document.body;e=e.parentNode)if(e.scrollTop)y-=e.scrollTop;
    return y;
    }
    function getX(el)
    {
    var x=0;
    while(el)
    {
    x+=el.offsetLeft;
    el=el.offsetParent;
    }
    return x;
    }
    function tips(obj,width,str)
    {
    obj.onblur = function(){document.getElementById("tips").style.display="none";};
    var x=getX(obj);
    var y=getY(obj);
    var l=x;
    var t=y;
    var popObj=document.getElementById("tips");
    if(popObj!=null)
    {
    popObj.innerHTML="<div style=\"background:#ffc;border:1px solid #000;padding:5px 0px 3px 3px;white-space:nowrap;width:"+ width +"px;\">"+str+"</div><div style=\"font-size:14px; color:#000;height:12px; margin-top:-1px; padding-left:5px;border:0px;\">ˇ</div>";
    popObj.style.display="inline";
    var menu_h=popObj.offsetHeight;
    t-=menu_h-13;
    popObj.style.left=l+"px";
    popObj.style.top=t+"px";
    }
    }