zoukankan      html  css  js  c++  java
  • 获取局部DIV的滚动条当前点击位置定位

    VoucherDetailInfoPanel 是div 的ID
    TextBox1 是临时存放值得控件
    75  是指减去头标题高度
    前台脚本如下:
    function GetPostion(e)
        {
            var element = document.getElementById("<%=VoucherDetailInfoPanel.ClientID %>");
            if( document.selection)
            {
                var range = document.selection.createRange();
                var stored_range = range.duplicate();
                stored_range.moveToElementText( element );
                stored_range.setEndPoint( 'EndToEnd', range );
                element.selectionStart = stored_range.text.length - range.text.length;
                element.selectionEnd = element.selectionStart + range.text.length;
                document.getElementById("<%=TextBox1.ClientID %>").value=element.selectionStart;
             }
        }
      function GetScrollTop() {
        //debugger;
                var div = document.getElementById("<%=VoucherDetailInfoPanel.ClientID %>");            
                div.scrollTop =document.getElementById("<%=TextBox1.ClientID %>").value-75;
            }

    脚本或者这样也可以 Begin

        function GetPostion()
        {    //debugger;
            var element = document.getElementById("<%=VoucherDetailInfoPanel.ClientID %>");
            if( document.selection)
            {
               document.getElementById("<%=TextBox1.ClientID %>").value=element.scrollTop+75;
             }
        }
      function GetScrollTop() {
         //debugger;
                var div = document.getElementById("<%=VoucherDetailInfoPanel.ClientID %>");            
                div.scrollTop =document.getElementById("<%=TextBox1.ClientID %>").value-75;
            }
    End

    后台代码
    VoucherDetailGrid 列表控件 是GridView控件
     protected void VoucherDetailGrid_RowEditing(object sender, GridViewEditEventArgs e)
            {
                if (e.NewEditIndex != VoucherDetailGrid.EditIndex)
                {
                    int newEditRow = e.NewEditIndex;
                    EditRow(newEditRow);
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "", "<script language='javascript'>GetScrollTop();</script>", false);// 这是调用前台的脚本            
                }
            }

      protected void VoucherDetailGrid_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                int finSetCode = 0;
                int j = 0;
                if (ViewState[VIEWSTATE_FINSETCODE] != null)
                {
                    finSetCode = Int32.Parse(ViewState[VIEWSTATE_FINSETCODE].ToString());
                }
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    VoucherDetailGrid.Attributes.Add("onclick", "GetPostion(event);");  // 这是调用前台的脚本
                    for (int i = 1; i < VoucherDetailGrid.Columns.Count; i++)
                    {
                        DataControlField dgc = VoucherDetailGrid.Columns[i];
                        if (dgc.HeaderText != String.Empty)
                        {
                            TCcVoucherSettingInfo tCcVoucherSettingInfo = BizVoucherSetting.GetVoucherItemByName(finSetCode, dgc.HeaderText);
                            if (tCcVoucherSettingInfo != null)
                            {
                                string voucherSettingId = tCcVoucherSettingInfo.VoucherSettingID;
                                string itemValue = String.Empty;
                                if (tCcVoucherSettingInfo.ItemType == (int)VoucherItemType.Dimension)
                                {
                                    if (e.Row.FindControl(dgc.HeaderText + EDITTEXTBOX) != null)
                                    {
                                        bool isNo = BizFromAccount.IsFromAccountType(Convert.ToInt32(tCcVoucherSettingInfo.TypeValue),Convert.ToInt32(tCcVoucherSettingInfo.FinSetCode));
                                        TextBox txb = (TextBox)e.Row.FindControl(dgc.HeaderText + EDITTEXTBOX);
                                        string txbClient = txb.ClientID;
                                        txb.Attributes.Add("onclick", "rowAccount(\'" + e.Row.RowIndex + "\',\'" + isNo + "\');__showDivContainer(\'" + txbClient + "\',\'" + tCcVoucherSettingInfo.FinSetCode + "\',\'" + tCcVoucherSettingInfo.TypeValue + "\');__DropDownClick(\'" + this.cc_MemberSelector.ClientID + "_divContainer\',\'150px\',\'" + txbClient + "\');  __setPosition(\'" + this.cc_MemberSelector.ClientID + "_divContainer\')");
                                        txb.Attributes.Add("isAccount", "true");
                                        txb.Attributes.Add("TypeValue", tCcVoucherSettingInfo.TypeValue);
                                        
                                    }
                                 
                                }
                            }
                        }
                    }
                }           
            }

  • 相关阅读:
    禁止网页右键、复制、另存为方法
    js循环99乘法口诀
    js点击判断显示或隐藏-21
    js下拉框-5
    js下拉框-4
    纯css下拉
    asp.net core 关于同步等待异步坑及解决办法
    net core http请求响应中间件 及全局异常中间件小计
    生产环境 前后端分离部署 https 跨域cors netcore3.1 部署小计
    csrediscore实现分布式锁 小计
  • 原文地址:https://www.cnblogs.com/liufei88866/p/2240929.html
Copyright © 2011-2022 走看看