jquery masked input make first two digits as non-editable

那年仲夏 提交于 2019-12-06 14:22:01

问题


Hi I'm currently using the jquery masked input and I want to make the first two digits as permanent numbers. For example, I have a number like (09)191-234-567

(09) are permanent mask while the following 9 digits are editable.

IF I do this, $("#phone").mask("(99) 999-999-999"); all digits are editable. I tried searching but found no luck.

Thanks in advance.


回答1:


The maskedinput plugin (which I believe you're referring to) allows you to define your own masks.

This means you can add your own masking character for numbers (#, for example), and remove the masking definition for 9 so that it no longer does anything.

$.mask.definitions['#'] = $.mask.definitions['9'];  //Set # to do what 9 does
$.mask.definitions['9'] = null;                     //Remove 9 as a masking character
$("input").mask("(09) ###-###-###");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.min.js"></script>
<input type="text">


来源:https://stackoverflow.com/questions/51413800/jquery-masked-input-make-first-two-digits-as-non-editable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!