if(e.target.id == "cited"){
alert(e.target.innerHTML);
if (document.getElementById(e.target.id).innerHTML == "[1]") {
display = "sometext1";
}
else if (document.getElementById(e.target.id).innerHTML == "[2]") {
display = "sometext2";
}
else if (document.getElementById(e.target.id).innerHTML == "[3]") {
display = "sometext3";
}
好吧,当我将鼠标悬停在我的 [3] 上时,它会显示“sometext2”,而它应该显示“sometext3”。[2] 和 [3] 在同一页上。我确实添加了一个快速调试,以查看它是否通过执行以下操作获取错误的 innerHTML:
alert(e.target.innerHTML);
当我将鼠标悬停在警报消息中时,它会显示正确的,但我不知道为什么它显示错误的工具提示。这里有什么帮助吗?
document.onmousemove = function(e)
{
// e.target, e.srcElement and e.toElement contains the element clicked.
var x = e.pageX;
var y = e.pageY;
var display;
if(e.target.id == "cited"){
// alert(e.target.innerHTML);
if (document.getElementById(e.target.id).innerHTML == "[1]") {
display = "sometext1";
}
else if (document.getElementById(e.target.id).innerHTML == "[2]") {
display = "sometext2";
}
else if (document.getElementById(e.target.id).innerHTML == "[3]") {
display = "sometext3";
}
document.getElementById("toolTip").style.top = y-50+"px";
document.getElementById("toolTip").style.left = x+"px";
document.getElementById("toolTip").style.visibility = "visible";
document.getElementById("toolTip").innerHTML = "<p>"+display+"</p>";
}
else {
document.getElementById("toolTip").style.visibility = "hidden";
}