怎样用JS获取ASP.NET服务器控件的客户端ID

虽然简单,不过曾经困扰多时,还是记录一下吧。

 

来源:http://mou518.blog.163.com/blog/static/1756052222010111434428828/

 

因为经常服务器控件在运行编译后ID是变化了的,如

<asp:TextBox ID="txtName"runat="server"></asp:TextBox>

运行编译后的结果可能是

<input name="ctl00$ContentPlaceHolder1$txtName " type="text" id="ctl00_ContentPlaceHolder1_ txtName" />

 

如果直接用document . getElementById(“txtName”)是获取不了的,

要用 document. getElementById(“<%= txtName.ClientID%>”)

 

 

相关文章:http://www.cnblogs.com/sophist/archive/2011/05/19/2050731.html

 

posted on 2015-04-06 14:00  华山青竹  阅读(380)  评论(0编辑  收藏  举报

导航