j查询在使用标记时不起作用<form>



当我在解决方案中使用表单标签时,Jquery asp.net controls.so 没有拧。我正在尝试多种技术,但它不起作用。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#bt1").click(function () {
                $("#p1").hide(2000);
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p runat="server" id="p1">this is asp.net</p>
        <asp:Button ID="bt1" Text="click" runat="server"/>
    </div>
        </form>
</body>
</html>

由于您使用的是 ASP.NET 并且bt1是您需要使用 Control.ClientID 的按钮服务器控件。

<%= bt1.ClientID %>将获取由 ASP.NET 生成的 HTML 标记的控件 ID。

$("#<%= bt1.ClientID %>").click(function () {
    $("#<%= p1.ClientID %>").hide(2000);
});

您可以使用ClientIDMode.Static模式,然后可以继续使用现有代码。但是我不会推荐它。

最新更新