我希望在以下网站上获得相同的效果:
http://www.kpf.com/projectlist.asp?T=4
在鼠标悬停图像时,相应的文本突出显示,反之亦然.
我在论坛上找到了一个Javascript解决方案.因为我的帖子中不能包含2个超链接,所以我复制粘贴了以下解决方案:
div代码
<div style="width:400;height:500;" onmouseover="hightlight()" onmouseout="removehightlight()"><span id="textspan" >This is a test div to show mouseover</span><img id="imgsrc" src="/images/test.gif" /></div>
Run Code Online (Sandbox Code Playgroud)
JavaScript的
<script language="javascript">
function hightlight()
{
document.getElementById("textspan").style.color = "blue";
document.getElementById("imgsrc").style.border = "1px solid blue";
//document.getElementById("textspan").setStyle("color","blue");
//document.getElementById("imgsrc").setStyle("border","1px solid blue");
}
function removehightlight()
{
document.getElementById("textspan").style.color = "black";
document.getElementById("imgsrc").style.border = "0px solid blue";
}
</script>
Run Code Online (Sandbox Code Playgroud)
但是,此解决方案适用于同一div中的图像和文本.我的图像和文本位于两个独立的div中,如下所示:
JavaScript的
function hightlight()
{
document.getElementById("textspan").style.text = "underline";
document.getElementById("imgsrc").style.border = "5px solid #005596";
}
function removehightlight()
{
document.getElementById("textspan").style.text = "none";
document.getElementById("imgsrc").style.border = "5px solid white";
}
Run Code Online (Sandbox Code Playgroud)
文本 …