• JavaScript实现div相对于input的绝对定位[实例:C#用户控件dropDownList]


    <%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
    <%@ Control Language="c#" AutoEventWireup="false" Codebehind="SelUnit.ascx.cs" Inherits="DXK.Web.component.SelUnit" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
    <script type="text/javascript">
        
    //Sel_Text.onclick = function()
        function clickSel(obj)
        
    {    
            
    if(divTree.style.display == 'none')
            
    {
                divTree.style.display 
    = '';    
                divTree.style.top 
    = findOffsetTop(obj) + obj.offsetHeight;            
                divTree.style.left 
    = findOffsetLeft(obj);
            }

            
    else
            
    {
                divTree.style.display 
    = 'none';            
            }

        }

        document.onclick 
    = function()
        
    {
            
    var the_obj = event.srcElement;
            
    if ((the_obj.id.indexOf('_Sel_Text') == -1&& (get_ElementById(the_obj, 'divTree') == null))
            
    {
                
    if(divTree.style.display == '')
                    divTree.style.display 
    = 'none';    
            }

        }

        
    function get_ElementById(the_ele,the_id)
        
    {
            the_id 
    = the_id.toLowerCase();
            
    if(the_ele.id.toLowerCase()==the_id)return the_ele;
            
    while(the_ele=the_ele.offsetParent){
                
    if(the_ele.id.toLowerCase()==the_id)return the_ele;
            }

            
    return(null);
        }

        
    function dodblclick(objTV, UCTag) 
        

            
    if(objTV.getTreeNode(objTV.clickedNodeIndex)!=undefined)
            
    {
                document.getElementById(UCTag
    +'_Sel_Text').value = objTV.getTreeNode(objTV.clickedNodeIndex).getAttribute("Text");
                document.getElementById(UCTag
    +'_Sel_Value').value = objTV.getTreeNode(objTV.clickedNodeIndex).getAttribute("NodeData");    
                divTree.style.display 
    = 'none';    
            }

        }
     
        
    function findOffsetTop(o)
        
    {
            
    var t = 0;
            
    if (o.offsetParent)
            
    {
                
    while (o.offsetParent)
                
    {
                    t 
    += o.offsetTop;
                    o  
    = o.offsetParent;
                }

            }

            
    return t;
        }

        
    function findOffsetLeft(o)
        
    {
            
    var t = 0;
            
    if (o.offsetParent)
            
    {
                
    while (o.offsetParent)
                
    {
                    t 
    += o.offsetLeft;
                    o  
    = o.offsetParent;
                }

            }

            
    return t;
        }

    </script>
    <input id="Sel_Text" style="BACKGROUND-POSITION-X: right; BACKGROUND-IMAGE: url(../images/seltip.jpg); WIDTH: 150px; CURSOR: pointer; BACKGROUND-REPEAT: no-repeat"
        readOnly type
    ="text" runat="server"> <INPUT id="Sel_Value" type="hidden" runat="server">
    <DIV id="divTree" style="BORDER-RIGHT: black 1px groove; BORDER-TOP: black 1px groove; DISPLAY: none; OVERFLOW: auto; BORDER-LEFT: black 1px groove; WIDTH: 240px; BORDER-BOTTOM: black 1px groove; POSITION: absolute; HEIGHT: 350px"><iewc:treeview id="tvUnitList" runat="server" BorderWidth="0px" BorderStyle="None"
            Indent
    ="20" SelectExpands="True" ShowToolTip="False"></iewc:treeview></DIV>
    .cs后台代码
  • 相关阅读:
    原型设计
    简单APP——ToDoList的二次开发(日期规范化+构建搜索栏)
    Java基本语言篇
    C++中各种常用转换汇总学习
    语言篇swift
    洛谷P2384 最短路,积化加
    洛谷P4568 分层图最短路
    【洛谷P1962】矩阵快速幂求Fibonacii数列
    vue-cli教程
    单页应用原理
  • 原文地址:https://www.cnblogs.com/ding0910/p/898313.html
Copyright © 2020-2023  润新知