日期:2014-05-16  浏览次数:20368 次

鼠标点击组件相应的div显示问题
<div   id= "ly1 "   style= "position:absolute;   width:600px;   left:   -100px;   display:none;top:17px;   visibility:   hidden;   overflow:   hidden; ">
<table   width= "400 "border= "0 "> <tr> <td> xxxxxxxxxxxxx </td </tr> </talbe>
</div>

<input   type= "text "   />   <br> <br>
<input   type= "text "   /> br> <br>
<input   type= "text "   />


比如这段代码,现在要求点击每个文本框时这个div显示在文本框的右边,click事件里怎么写?

------解决方案--------------------
document.getElementById( "ly1 ").style.display= "block ";

document.getElementById( "ly1 ").style.top = 537 + "px ";
document.getElementById( "ly1 ").style.left = 537 + "px ";

先让它显示出来 然后在设置位置
------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= "lap1983 ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
<script language= "javascript ">
function ControlDiv(obj)
{
var lblLyl = document.getElementById( "ly1 ");
alert(obj.offsetTop);
lblLyl.style.left = obj.clientLeft + obj.clientWidth + 10;
lblLyl.style.top = obj.offsetTop;
lblLyl.style.display = " ";
lblLyl.style.visibility = " ";
}
</script>
</HEAD>

<BODY>
<div id= "ly1 " style= "position:absolute; width:600px; left: -100px; display:none;top:17px; visibility: hidden; overflow: hidden; ">
<table width= "400 "border= "0 "> <tr> <td> xxxxxxxxxxxxx </td> </tr> </table>
</div>

<input type= "text " onclick= "ControlDiv(this); " /> <br> <br>
<input type= "text " onclick= "ControlDiv(this); "/> <br> <br>
<input type= "text " onclick= "ControlDiv(this); "/>
</BODY>
</HTML>

------解决方案--------------------
用XMLHttp向后台请求数据,然后返回时用JavaScript写进DIV的innerHTML中