div弹出菜单显示位置无法控制,求帮助!
我想做一个点击textbox就在文本框下方显示出一个div的pop菜单,目前能显示出来,但是就是位置不对,找了很久的原因都没有找到,希望那我高手可以帮我看看,解决一下,万分感谢!html:
<div class="center_content_hasboder">
<form action="classes_add.asp" method="post">
<ul class="ul_form_item">
<li>班级 ID:<input name="cls_id" type="text" readonly="readonly" /></li>
<li>班级名称:<input name="cls_name" type="text" /></li>
<li>所属年级:<input name="grd_blong" id="grd_blong" type="text" onclick="ShowPopMenu('GradesMenu',this)"/></li>
<div class='PopupMenu_wid150' name='GradesMenu' id='GradesMenu'>GR2019 ,高2019级 </div>
<li>班级负责人:<input name="cls_ceo" type="text" onclick="ShowPopMenu('GradesMenu',this"/></li>
<li>语文:<input name="km_chn" type="text" /></li>
<li>数学:<input name="km_mat" type="text" /></li>
<li>英语:<input name="km_eng" type="text" /></li>
<li>物理:<input name="km_phy" type="text" /></li>
<li>化学:<input name="km_che" type="text" /></li>
<li>生物:<input name="km_bio" type="text" /></li>
<li>政治:<input name="km_pli" type="text" /></li>
<li>历史:<input name="km_his" type="text" /></li>
<li>地理:<input name="km_geo" type="text" /></li>
</ul>
<ul class="ul_form_item">
<li>
<input name="cmd_ok" type="submit" value="新 增" />
<input name="cmd_reset" type="reset" value="重 置" />
</li>
</ul>
</form>
</div>
css:
.PopupMenu_wid150{
float:left;
display:block;
width:150px;
height:auto;
margin:auto;
padding:3px 10px;
color:color:#333;
border:#CCC 1px solid;
visibility:hidden;
position:absolute;
background:#add;
}
.PopupMenu_wid150 li{
width:100%;
line-height:25px;
}
js代码:
//显示和隐藏
function MM_showHideLayers() {
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3)
with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
}
function setPosition1(divid,txt){
var txtObject=document.getElementById(txt);
var divObject=document.getElementById(divid);
divObject.style.top=txtObject.offsetTop + txtObject.offsetHeight;
divObject.style.left=txtObject.offsetLeft;}
function ShowPopMenu(divid,txt){
MM_showHideLayers(divid,'','show');
setDivPosition(divid,txt);
}