控制DIV自动调整(防Select、Flash、Object遮盖)

本文介绍了一个使用JavaScript实现的用户列表弹窗功能。该功能通过点击按钮显示或隐藏包含多个用户选项的弹窗,并能一键全选所有用户。此外,还详细展示了如何定位弹窗并确保其始终位于页面可见区域内。
 
        <script language="javascript">
            
function SelectAllUser(controlID)
            
...{
                
var ele = event.srcElement; 
                
if(ele.type=='checkbox'
                
...
                    
var checkBoxs = document.getElementsByTagName( "INPUT" );
                    
for(var i=0;i<checkBoxs.length;i++
                    
...
                        
if(checkBoxs[i].type=='checkbox' && checkBoxs[i].id.indexOf("QCheckBoxUserList"!= -1
                        
...{
                            checkBoxs[i].checked 
= ele.checked;
                        }

                    }

                }
 
            }

            
            
function HideUserList(controlID)
            
...{
                document.getElementById(controlID).style.display 
= "none";
                
return false;
            }

            
            
function ShowUserList(controlID)
            
...{
                
//document.getElementById("MailDIV").style.display = "none";
                //document.getElementById("UserListDIV").style.display = "none";                
                var the = event.srcElement;
                
var div = document.getElementById(controlID);
                
//alert(document.body.clientHeight + "  " + event.y + "  " + div.offsetHeight);
                if(document.body.clientHeight - event.y - 20 <= div.offsetHeight)
                
...{
                    div.style.top 
= event.y - div.offsetHeight;
                }

                
else
                
...{
                    div.style.top 
= event.y;
                }

                
if(div.offsetHeight == 0)
                
...{
                    div.style.top 
= event.y - 200;
                }
                
                div.style.right 
= document.body.clientWidth - event.x + 25;
                div.style.display 
= "block";
                
return false;
            }

        
</script>

只需要在我们的DIV前加IFrame作为底层

        <iframe style="position: absolute; z-index: 9; width: expression(this.nextSibling.offsetWidth);
            height: expression(this.nextSibling.offsetHeight); top: expression(this.nextSibling.offsetTop);
            left: expression(this.nextSibling.offsetLeft);"
 frameborder="0"></iframe>
        
<div id="UserListDIV" style="position: absolute; display: none; background-color: White;
            z-index: 19; width: 150px;"
>
            
<table>
                
<tr>
                    
<td>
                        
<BenQ:QCheckBox ID="QCheckBoxAll" runat="server" Text="All" AutoPostBack="false"
                            onclick
="javascript:SelectAllUser(this)" /><br>
                        
<BenQ:QCheckBox ID="QCheckBoxUserList0" runat="server" Text="Jason Xu" /><br>
                        
<BenQ:QCheckBox ID="QCheckBoxUserList1" runat="server" Text="Lionel Li" /><br>
                        
<BenQ:QCheckBox ID="QCheckBoxUserList2" runat="server" Text="Laker Yan" /><br>
                        
<BenQ:QCheckBox ID="QCheckBoxUserList3" runat="server" Text="Jason Xu" /><br>
                        
<BenQ:QCheckBox ID="QCheckBoxUserList4" runat="server" Text="Jason Xu" /><br>
                        
<BenQ:QCheckBox ID="QCheckBoxUserList5" runat="server" Text="Jason Xu" /><br>
                        
<BenQ:QCheckBox ID="QCheckBoxUserList6" runat="server" Text="Jason Xu" /><br>
                        
<BenQ:QCheckBox ID="QCheckBoxUserList7" runat="server" Text="Jason Xu" /><br>
                        
<BenQ:QCheckBox ID="QCheckBoxUserList8" runat="server" Text="Jason Xu" /><br>
                    
</td>
                
</tr>
                
<tr>
                    
<td style="text-align: center">
                        
<BenQ:QButton ID="QButtonSubmit" runat="server" Text="Save" Type="submit" />
                        
<span class="Span5"></span>
                        
<BenQ:QButton ID="QButtonCancel" runat="server" Text="Cancel" Type="common" OnClientClick="return HideUserList('UserListDIV');" />
                    
</td>
                
</tr>
            
</table>
        
</div>
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值