zoukankan      html  css  js  c++  java
  • getElementById() dosen't find <input type="hidden" runat="server"/>

    getElementById()  dosen't find <input type="hidden" runat="server"/>

    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <input id="divPosition" type="hidden" value="12" runat="server" />
    
    
    <div id="divScroller" style="overflow:scroll; margin-top:10px; height:505px; 100%" onscroll="GetDivPosition(this)">
    ...
    ...
    </div>
    
    
    ...
    </asp:Content>

    onscroll I am calling Javascript function "GetDivPosition(this)" and trying to save the sroll positon in hidden field. But the javascript function doesn't find the hidden field if I have runat="server"  attribute with hidden field. Here is the javascript function

    function GetDivPosition(divRef)
            {
                //alert(divRef.scrollTop);                        
                document.getElementById("divPosition").value = divRef.scrollTop;
                alert("hidden" + document.getElementById("divPosition").value);
            }

     

    A server contorl inside Content page will have some prefix added to its ID,when it is generated as HTML.so you'll have to access by using its ClientID like this.

    document.getElementById('<%=divPosition.ClientID%>').value=divRef.scrollTop;

    注意:使用<%=divPostion.ClientID%>的时候,这段js不能写在单独的文件中,必须写在aspx文件中才可以.

  • 相关阅读:
    2D单人姿态估计论文及代码地址
    pytorch-stacked-hourglass
    stacked-hourglass-networks
    Android ViewBadger
    Stacked Hourglass Networks in Pytorch
    BurstCamera
    Android camera library for taking multiple photos
    TakePhoto android
    PyTorch Tutorial
    LiveNVR传统安防摄像机互联网直播-二次开发相关的API接口
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/2670036.html
Copyright © 2011-2022 走看看