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

时间:2022-10-30 13:45:47
<%@ 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>