Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JSP:在特定坐标处定位DIV不起作用_Javascript_Java_Html_Css_Jsp - Fatal编程技术网

Javascript JSP:在特定坐标处定位DIV不起作用

Javascript JSP:在特定坐标处定位DIV不起作用,javascript,java,html,css,jsp,Javascript,Java,Html,Css,Jsp,我试图在输入框的坐标上放置一个Div。单击输入框后,DIV将启用并加载值,DIV上的任何选择都必须将值设置为输入框。除了输入框不在坐标上,而是在页面顶部之外,一切都正常 <div class="mRow"> <label for="SS">Special Subjects:</label> <span class="numLbls">1. </span><input type="text" name="ade" value="&l

我试图在输入框的坐标上放置一个Div。单击输入框后,DIV将启用并加载值,DIV上的任何选择都必须将值设置为输入框。除了输入框不在坐标上,而是在页面顶部之外,一切都正常

<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>
Javascript

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
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;
var tempY = 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}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  //document.Show.MouseX.value = tempX
  //document.Show.MouseY.value = tempY
  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);

  computeCoordinates();

  codeEl = el;
  alert(" Iam here");
  alert("document.Show.sMouseY.value:"+document.Show.sMouseY.value);  
  alert("document.Show.sMouseX.value:"+document.Show.sMouseX.value);
  divCodes.style.display="block";
  divCodes.style.top=document.Show.sMouseY.value;
  divCodes.style.left=document.Show.sMouseX.value;

}

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;
  }  


  document.Show.sMouseX.value = _x;
  document.Show.sMouseY.value = _y;
}

function hideThis(id)
{
  document.getElementById(id).style.display="none";
}
//检测浏览器是否为IE。
//如果不是IE,我们假设浏览器是NS。
var IE=文档。全部?真:假
var codeEl;
//如果NS,那就是!IE——然后设置鼠标捕捉
if(!IE)document.captureEvents(Event.MOUSEMOVE)
//设置为在MouseMove上使用getMouseXY函数
document.onmousemove=getMouseXY;
//用于固定鼠标x-y位置的临时变量
var-tempX=0;
var-tempY=0;
//var frm=document.dashboardSearchForm;
函数getMouseXY(e){
如果(IE){//如果浏览器是IE,则抓取x-y位置
tempX=event.clientX+document.body.scrollLeft
tempY=event.clientY+document.body.scrollTop
}否则{//如果浏览器为NS,则抓取x-y位置
tempX=e.pageX
tempY=e.pageY
}  
//捕捉NS4中可能的负值
如果(tempX<0){tempX=0}
如果(tempY<0){tempY=0}
//以名为show的形式显示位置值
//在名为MouseX和MouseY的文本字段中
//document.Show.MouseX.value=tempX
//document.Show.MouseY.value=tempY
返回真值
}
函数showCodeLookup(el,divName)
{
//隐藏首先显示的所有查找表
document.getElementById(“divSpec”).style.display=“无”;
var divcode=document.getElementById(divName);
计算坐标();
codeEl=el;
警惕(“我在这里”);
警报(“document.Show.sMouseY.value:+document.Show.sMouseY.value”);
警报(“document.Show.sMouseX.value:+document.Show.sMouseX.value”);
divcode.style.display=“block”;
divcode.style.top=document.Show.sMouseY.value;
divcode.style.left=document.Show.sMouseX.value;
}
函数设置代码(divName,code)
{
var divEl=document.getElementById(divName);
codeEl.value=代码;
divEl.style.display=“无”;
}
函数computeCoordinates()
{
var isIE=document.all?真:假;
var ScrollTop=document.body.ScrollTop;
var_x=tempX;
var _y=tempY;
如果(ScrollTop==0)
{
if(window.pageYOffset)
ScrollTop=window.pageYOffset;
其他的
ScrollTop=(document.body.parentElement)?document.body.parentElement.ScrollTop:0;
}
如果(isIE)
{
_x=tempX+document.body.scrollLeft;
_y=tempY+scrollpop;
}  
document.Show.sMouseX.value=\u x;
document.Show.sMouseY.value=\u y;
}
函数hideThis(id)
{
document.getElementById(id).style.display=“无”;
}

有什么建议吗。我添加了警报showCodeLookup(),它为我提供了正确的坐标,比如1036代表Y,536代表X。

我在Chrome上测试了你的代码,发现在你的js代码
文档中.Show.sMouseY.value
文档.Show.sMouseX.value
都是空的或未定义的。因此,当您将这些值分配给div
divSpec
时,它没有将其定位到所需的坐标。相反,我对您的js代码进行了某些更改,如下所示:

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";
}

专题:
1.
2.
3.
dddddddd

我如上所述替换了代码,但没有看到任何更改。div仍然位于页面顶部。顺便说一句,我对X和Y坐标给出了警告,我的代码和你的代码给出了相同的坐标。只是让你知道我的代码也选择了正确的坐标。我已经用工作代码更新了我的答案。让我知道这是否有效
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
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;
var tempY = 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}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  //document.Show.MouseX.value = tempX
  //document.Show.MouseY.value = tempY
  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);

  computeCoordinates();

  codeEl = el;
  alert(" Iam here");
  alert("document.Show.sMouseY.value:"+document.Show.sMouseY.value);  
  alert("document.Show.sMouseX.value:"+document.Show.sMouseX.value);
  divCodes.style.display="block";
  divCodes.style.top=document.Show.sMouseY.value;
  divCodes.style.left=document.Show.sMouseX.value;

}

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;
  }  


  document.Show.sMouseX.value = _x;
  document.Show.sMouseY.value = _y;
}

function hideThis(id)
{
  document.getElementById(id).style.display="none";
}
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";
}