【问题标题】:I can't make JQueryUI work with ASP.net server controls我不能让 JQueryUI 与 ASP.net 服务器控件一起工作
【发布时间】:2012-02-20 17:23:56
【问题描述】:

很抱歉,我找不到任何答案。

这是一个已知问题吗?有解决办法吗?

请帮忙。我想在 ASP.net Server Controls 中使用 JQueryUI

示例脚本

$(document).ready(function () {
           $('#txtSearch').datepicker({
               showPeriod: true,
               showLeadingZero: true
           });
           $('#Text1').datepicker({
               showPeriod: true,
               showLeadingZero: true
           });
       });

示例标记

    <input id="Text1" type="text"/>
    <asp:TextBox ID="txtSearch" runat="server" Height="21px" Width="196px">
    </asp:TextBox>

问题是它在普通的 html 控件上工作,而不是在 asp 控件上 我感谢任何帮助。谢谢!

【问题讨论】:

    标签: javascript asp.net jquery-ui


    【解决方案1】:

    试试下面的。如果您“查看源代码”页面,您将看到 asp.net 控件的 ID 已动态更改。使用下面的内容,您可以访问 txtSearch html 元素的动态生成的 ID:

    $(document).ready(function () {
               $('#<%=txtSearch.ClientID%>').timepicker({
                   showPeriod: true,
                   showLeadingZero: true
               });
               $('#Text1').timepicker({
                   showPeriod: true,
                   showLeadingZero: true
               });
           });
    

    【讨论】:

      【解决方案2】:

      当呈现服务器控件时,控件的 ID 会更改。所以你的 txtSearch id 会变成类似 ct001_txtSearch 的东西。 这就是 jquery 找不到它的原因,因为它正在寻找 id 'txtSearch' 但没有控制 id 'txtSearch'。

      尝试使用 clientID 来引用 id。

      【讨论】:

        【解决方案3】:
        【解决方案4】:

        一个快速的方法是:只需使用 html 控件并将其标记为 runat="server"

        Es:

        <input type="text" id="Textbox1" runat="server">
        

        【讨论】:

        • 使用 firebug 之类的工具(或简单地查看 html 页面的源代码)并找出 asp.net 为该控件生成的 id 是什么。或者只是将一个 css 类添加到您的控件并将 jquery 日历绑定到该类而不是 id。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-07-07
        • 1970-01-01
        • 2010-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多