简体   繁体   English

JavaScript工具提示帮助和颜色更改

[英]Javascript tooltip help and color change

I am fairly new with Javascript. 我对Java相当陌生。 Now, what I need is that I have a link in my projectXYZ which leads to another projectABC. 现在,我需要的是我的projectXYZ中有一个链接,该链接指向另一个projectABC。 I need to change the color of the link and show a tooltip dialog for the MouseOver event of the link. 我需要更改链接的颜色,并为链接的MouseOver事件显示一个工具提示对话框。

I tried to change the color, but could not succeed with the tooltip. 我试图更改颜色,但使用工具提示无法成功。 Is there a combined solution which fulfills these requirements ? 是否有满足这些要求的组合解决方案?

Thanks in advance. 提前致谢。

Usually it is said to be sufficient to add a 'title' attribute in tour DIV's and it will show up as tooltip on mouse-hover. 通常说来,在巡回DIV中添加一个“ title”属性就足够了,它将作为鼠标悬停时的工具提示显示。

But to make a basic tooltip with proper positioning, you can use the below. 但是要使基本工具提示具有正确的位置,可以使用以下内容。 I have used it and it works !! 我用过它,它的工作原理!

JS (will have two mwthods, showTip and hideTip) : JS(将具有两个方法,showTip和hideTip):

<script type="text/javascript">
function showtip(e,message) {
var x=0;
var y=0;
var m;
var h;
if(!e)
var e=window.event;
if(e.pageX||e.pageY) { x=e.pageX;  y=e.pageY;  }
else if(e.clientX||e.clientY)
{ x=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;y=e.clientY+document.body.scrollTop+document.documentElement.scrollTop;}
m=document.getElementById('myTooltip');
if((y>10)&&(y<450))
{  m.style.top=y-4+"px";  }
else{  m.style.top=y+4+"px";  }
var messageHeigth=(message.length/20)*10+25;
if((e.clientY+messageHeigth)>510)
{  m.style.top=y-messageHeigth+"px"; }
if(x<850) { m.style.left=x+20+"px";  }
else{  m.style.left=x-170+"px";  }
m.innerHTML=message;m.style.display="block";m.style.zIndex=203;
}

function hidetip(){
var m;
m=document.getElementById('myTooltip');m.style.display="none";
}
</script>

CSS: CSS:

<style type="text/css">
#myTooltip{padding: 5px; background-color: #FFF8DC;  border: 1px solid #DEB887; width:180px;font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #6b6b6b; display:none; position:absolute;left:0px;top:0px; }
</style>

And the HTML (will have an extra DIV below the href to show tooltip): HTML(在href下方将有一个额外的DIV来显示工具提示):

<a href="javascript:void(0)" onmouseover="showtip(event, 'Sample tooltip text');"
onmouseout="hidetip();">Hover mouse to see tooltip text.</a>
<div id="myTooltip" ></div>

Hope it helps !! 希望能帮助到你 !!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM