ClientID 获取服务端控件,客户端id的方法

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication5.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="jquery-2.1.0-beta3.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#btn").click(function () {

                alert($("#"+"<%=TextBox1.ClientID %>").val());
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <input type="button"  value="点击" id="btn"  />
        </div>
    </form>
</body>
</html>

 

posted @ 2014-04-16 15:53  crazyair  阅读(576)  评论(0编辑  收藏  举报