[英]javascript. Label for element with generated ID
I would like to do this 我想这样做
<label class="test" for="myButton" >This is a label</label>
<input type="button" id="myButton" value="click me" />
for some buttons in a page that receive IDs on page load: genereated server side (asp 3.5). 对于页面加载时接收ID的页面中的某些按钮:生成的服务器端(asp 3.5)。
How do I get the right id in the 'for' attribute of the label element for each button? 如何在每个按钮的label元素的'for'属性中获取正确的ID?
Thanks 谢谢
You can use AssociatedControlID
property of Label
: 您可以使用
Label
AssociatedControlID
属性:
<asp:Label class="test" runat="server" AssociatedControlID="myButton">
This is a label</asp:Label>
<asp:Button ID="myButton" runat="Server" Text="click me" />
Source: AssociatedControlID . 来源: AssociatedControlID 。
try this 尝试这个
<label class="test" for="<%= myButton.ClientID %>" >This is a label</label>
<input type="button" id="myButton" runat="server" value="click me" />
this will use the same id generated by asp.net on the server side 这将使用服务器端由asp.net生成的相同ID
您可以将输入标签包装在标签标签中,并且不需要for / id
<label>This is a label <input type="button"/></label>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.