本文介绍了.net与母版页如何使用变量在.aspx页面上使用javascript查找控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Hello...I am trying to use javascript document.getElementById() to find a server control on my page.The page uses a master page.The challenge is the control has a variable name.In this case, these are textboxes with IDs like customer_123, customer_654The javascript function is passed a variable for each control like thisidI can always use something like document.getElementByID('ctl00_maincontent_customer' + thisid)).valueBut, I do not like using that hard-codes syntax and prefer to usedocument.getElementByID('<%=thiscontrolid.ClientID%>').valueI cannot find a way to create the [thiscontrolid] as a variable whose value is partially passed to the function.For example. Something like:function getMyControl(thisid){ document.getElementByID("<%=customer_[thisid].ClientID%>").value}But I have not been able to find a syntax that will allow me to do this.Any suggestions would be appreciated.What I have tried:<pre>document.getElementByID("<%=customer_" & thisid.ClientID%>").value 推荐答案 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"><br /> <div runat="server" id="customer_1"><br /> I am first control</div><br /> <div runat="server" id="customer_2"><br /> I am second control</div> <br /></asp:Content> 在MasterPage上使用以下脚本: On MasterPage use below script:<script type="text/javascript" src="jquery-1.11.0.min.js"></script> //需要提供jquery路径 //need to give jquery path<script type="text/javascript"> 这篇关于.net与母版页如何使用变量在.aspx页面上使用javascript查找控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-03 13:17