[英]asp.net textbox mask using jquery not working
I'm trying to use the jquery mask to apply to an ASP.NET web form textbox
. 我正在尝试使用jquery掩码应用于ASP.NET Web窗体textbox
。 Nothing I do works... what am I missing? 我没有任何工作...我想念什么?
<script type="text/javascript" src="/js/jquery.maskedinput-1.2.2.js"></script>
<script type="text/javascript" src="/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
$(function() {
$("#phone").mask("999-999-9999");
});
</script>
This is the text box code: 这是文本框代码:
<asp:TextBox runat="server" ID="phone" CssClass="rightsection" ToolTip="Please enter a phone number."></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="phone" Display="Dynamic" ForeColor="Red" Text="Required field" ValidationGroup="formfields" />
the textbox's id changes when it gets rendered to include the parent containers id, you can get the rendered id with ClientID like this 文本框的ID在呈现时会更改为包括父容器ID,您可以使用ClientID这样获得呈现的ID,如下所示
$("#<%= phone.ClientID%>").mask("999-999-9999");
The ClientID value is generated by concatenating the ID values of each parent naming container with the ID value of the control. 通过将每个父命名容器的ID值与控件的ID值串联在一起来生成ClientID值。 In data-binding scenarios where multiple instances of a control are rendered, an incrementing value is inserted in front of the control's ID value. 在呈现控件的多个实例的数据绑定方案中,在控件的ID值的前面插入一个递增值。 Each segment is separated by an underscore character (_). 每个段由下划线字符(_)分隔。
This is the solution: 这是解决方案:
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="js/jquery.maskedinput.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.