I have searched a lot and found out same kind of question but not exactly same and didn't find satisfactory answer. So thought, Should ask that more specific. Using Jquery mask plugin, I would like my cursor at the beginning always no matter which positon I click. If I click into that textbox, cursor should be at the beginning. with my below code. wherever I click into the textbox, cursor gets that particular positon. How to avoid that?
<asp:TextBox ID="tbMobile" CssClass="ContactNumber" runat="server" onfocus="GetPhoneMask();" MaxLength="15" placeholder="555-555-5555" ValidationGroup="Application"></asp:TextBox>
function GetPhoneMask() {
$(".ContactNumber").mask("999-999-9999", { autoclear: false });
}
Live link https://dotnetfiddle.net/Gipb8h
I changed the phone class name.
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebFormsPW._Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.js"></script>
<script type="text/javascript">
$(function () {
$('.phone_us').mask('(000) 000-0000');
})
//took out
//function GetPhoneMask() {
// $(".ContactNumber").mask("999-999-9999", { autoclear: false });
//}
</script>
<%-- took out onfocus="GetPhoneMask();"--%>
<asp:TextBox ID="tbMobile" CssClass="phone_us" runat="server" MaxLength="15" placeholder="555-555-5555" ValidationGroup="Application"></asp:TextBox>
</asp:Content>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.