代码之家  ›  专栏  ›  技术社区  ›  Sam Daniel

在javascript中找不到隐藏文本的Id

  •  0
  • Sam Daniel  · 技术社区  · 7 年前

    这是我的aspx页面

    <telerik:GridTemplateColumn SortExpression="PrintColumn" DataField="PrintColumn" HeaderText=""
        HeaderStyle-Font-Bold="true">
        <ItemTemplate>
            <asp:HiddenField ClientIDMode="Static" ID="lblIDSIDPrint" runat="server" Value='<%# Eval("DSID") %>'/>
            <asp:HiddenField ID="lblDataDSPrint" runat="server" Value='<%# Eval("DataDS")%>'/>
            <asp:LinkButton Style="text-align: right; float: right;" ID="lbDSPrint" runat="server"
                OnClientClick="popWin">Print</asp:LinkButton>                                                     
        </ItemTemplate>
    </telerik:GridTemplateColumn>
    

    这是我的javascript

    function popWin() {
        var Dsid = document.getElementById('<%=lblIDSIDPrint.ClientID %>').value;
        var DataDs = document.getElementById('<%=lblDataDSPrint.ClientID %>').value;
        alert(Dsid);
        alert(DataDs);
    }  
    

    但我犯了个错误

    有什么建议吗。

    2 回复  |  直到 7 年前
        1
  •  1
  •   Death-is-the-real-truth    7 年前

    试着这样做:-

    var Dsid = document.getElementById('lblIDSIDPrint').value; alert(Dsid);
    
        2
  •  0
  •   Death-is-the-real-truth    7 年前

    尝试使用 $(document).find("#lblIDSIDPrint").val();