1 回答
TA贡献1765条经验 获得超5个赞
我已经在Chrome上测试了您的代码,发现在您的js代码中并且是空的或未定义的。因此,当您将这些值分配给 div 时,它并未将其定位到所需的坐标。相反,我已经在您的js代码中进行了某些更改,如下所示:document.Show.sMouseY.valuedocument.Show.sMouseX.valuedivSpec
var IE = document.all ? true : false
var codeEl;
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0;//declare
var tempY = 0;//declare
var mouseX = 0;
var mouseY = 0;
//var frm = document.dashboardSearchForm;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
} else { // grab the x-y pos.s if browser is NS
tempX = e.pageX
tempY = e.pageY
}
// catch possible negative values in NS4
if (tempX < 0) {
tempX = 0
}
if (tempY < 0) {
tempY = 0
}
return true;
}
function showCodeLookup(el, divName) {
//Hide any lookup tables that are displayed first
document.getElementById("divSpec").style.display = "none";
var divCodes = document.getElementById(divName);
codeEl = el;
computeCoordinates();
divCodes.style.display = "block";
divCodes.style.left = tempX; //(change here)assigning coordinate found
divCodes.style.top = tempY; //(change here)
}
function setCode(divName, code) {
var divEl = document.getElementById(divName);
codeEl.value = code;
divEl.style.display = "none";
}
function computeCoordinates() {
var isIE = document.all ? true : false;
var ScrollTop = document.body.scrollTop;
var _x = tempX;
var _y = tempY;
if (ScrollTop == 0) {
if (window.pageYOffset)
ScrollTop = window.pageYOffset;
else
ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
}
if (isIE) {
_x = tempX + document.body.scrollLeft;
_y = tempY + ScrollTop;
}
tempX = _x;//change here
tempY = _y;//change here
}
function hideThis(id) {
document.getElementById(id).style.display = "none";
}
(上面的代码已经在chrome上进行了测试,并且可以按接受的方式工作)
工作代码 :
var IE = document.all ? true : false
var codeEl;
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0; //declare
var tempY = 0; //declare
var mouseX = 0;
var mouseY = 0;
//var frm = document.dashboardSearchForm;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
} else { // grab the x-y pos.s if browser is NS
tempX = e.pageX
tempY = e.pageY
}
// catch possible negative values in NS4
if (tempX < 0) {
tempX = 0
}
if (tempY < 0) {
tempY = 0
}
return true;
}
function showCodeLookup(el, divName) {
//Hide any lookup tables that are displayed first
document.getElementById("divSpec").style.display = "none";
var divCodes = document.getElementById(divName);
codeEl = el;
computeCoordinates();
divCodes.style.display = "block";
divCodes.style.top = tempX +'px'; //(change here)assigning coordinate found
divCodes.style.left = tempY +'px'; //(change here)
}
function setCode(divName, code) {
var divEl = document.getElementById(divName);
codeEl.value = code;
divEl.style.display = "none";
}
function computeCoordinates() {
var isIE = document.all ? true : false;
var ScrollTop = document.body.scrollTop;
var _x = tempX;
var _y = tempY;
if (ScrollTop == 0) {
if (window.pageYOffset)
ScrollTop = window.pageYOffset;
else
ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
}
if (isIE) {
_x = tempX + document.body.scrollLeft;
_y = tempY + ScrollTop;
}
tempX = _x; //change here
tempY = _y; //change here
}
function hideThis(id) {
document.getElementById(id).style.display = "none";
}
.lookupTable
{
display:none;
padding:5px;
z-index:10;
font-size: 10px;
position: absolute;
border: 2px solid #933;
background-color:white;
width: 220px;
height:180px;
}
<html>
<body>
<div class="mRow">
<label for="SS">Special Subjects:</label>
<span class="numLbls">1. </span><input type="text" name="ade" value="<%=ade[0]%>" size="6" maxlength="6" onclick="showCodeLookup(this, 'divSpec')" />
<span class="numLbls">2. </span><input type="text" name="ade" value="<%=ade[1]%>" size="6" maxlength="6" onclick="showCodeLookup(this, 'divSpec')" />
<span class="numLbls">3. </span><input type="text" name="ade" value="<%=ade[2]%>" size="6" maxlength="6" onclick="showCodeLookup(this, 'divSpec')" />
</div>
<div id="divSpec" class="lookupTable" onClick="hideThis(this.id)">
<table>
ddddddddd
</table>
</div>
</body>
</html>
添加回答
举报