日期:2014-05-20  浏览次数:20503 次

重开帖:根据div位置调整web form位置,内附代码
具体是一个用div做的日历控件,很复杂,我就帖个示范:

这是一个显示div的函数
popCalendar(var   x,var   y)
{
//
if(div没有超出窗体)
{
div.style.left   =   x   ;
div.style.top   =   y   ;
div.style.display     " ";
}
else
{
...先调整窗体
div.style.left   =   x   ;
div.style.top   =   y   ;
div.style.display     " ";
}
}
<button   onclick= 'popCalendar(100,200) '   name= 'btnPop '   />


------解决方案--------------------
调整web form的位置?不太明白,能不能说的明白点? web form是指??窗口?
------解决方案--------------------
窗体是一个什么概念?winform中就是指窗口。 webform中呢? 指什么? 是指窗口吗?
------解决方案--------------------
就是页面啊 比如显示日历的时候 只能看到上面一截的话 就自动把页面望下拉高 ======= 其实不用div,用popwindow,就不用考虑这个问题了。
------解决方案--------------------
是这个意思吗? <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <BR> <DIV id= "div1 " style= "display:none;width:400px;height:600px;border:solid 1px black "> </DIV> <input type= "button " value= "Click " onclick= 'popCalendar(100,200) ' name= 'btnPop ' />


<SCRIPT language= "javascript "> <!-- function popCalendar( x, y) { // var div = document.all.div1; div.style.display = " "; if(div.offsetHeight+div.offsetTop> document.body.scrollTop) { // alert(div.offsetTop); window.scrollTo(0,div.offsetTop); div.style.left = x ; div.style.top = y ; //div.style.display = " "; } else { div.style.left = x ; div.style.top = y ; div.style.display = " "; } } //--> </SCRIPT>
------解决方案--------------------
好,再看看.
------解决方案--------------------
说明:这个不符合w3c标准,仅在ie下有效. <TABLE width= "100% "> <TR> <TD height= "1200px "> 这是表格 </FONT> </TD> <TD> <DIV id= "div1 " style= "position:absolute;display:none;width:400px;height:400px;border:solid 1px black "> </DIV> <INPUT type= "button " value= "Click " onclick= 'popCalendar(this) ' name= 'btnPop ' /> </TD> </TR> </TABLE>


<SCRIPT language= "javascript "> <!-- function popCalendar(btn) { //alert(document.body.offsetHeight); var ary = GetElementPos(btn); var div = document.all.div1; div.style.display = " "; if(ary[0] + div.offsetHeight> document.body.offsetHeight +document.body.scrollTop) { document.body.scrollTop+= ary[0] + div.offsetHeight-(document.body.offsetHeight +document.body.scrollTop)+20; } div.style.x = ary[0]; div.style.y = ary[1]; } //得到某一元素的绝对位置 function GetElementPos(obj) { var left = 0; var top = 0; if(obj.x) { left= obj.x; top = obj.y; }else if(obj.offsetParent) { while(obj.offsetParent) { left += obj.offsetLeft; top += obj.offsetTop; obj = obj.offsetParent; } } var ary = new Array(); ary[0] = left; ary[1] = top; return ary; } //--> </SCRIPT>
------解决方案--------------------
因此,要去掉网页第一行的. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">