如何在jQuery中格式化掩码文本框? [英] How to format mask textbox in jQuery?
本文介绍了如何在jQuery中格式化掩码文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网页表单,上面有使用jQuery代码屏蔽的文本框。
这是我的代码:
I have a web form that has textboxes on it that are masked using jQuery code.
Here is my code:
<head runat="server">
<title>jQuery Masked Input Demo</title>
<script src="Jquery Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="Jquery Scripts/jquery.maskedinput.js" type="text/javascript"></script>
<script type='text/javascript'>
$(document).ready(function () {
$.mask.definitions['~'] = "[+-]";
$("#TextBox1").mask("999,999,999,999");
$("#TextBoxY").mask("999,999,999,999");
$("#TextBox1").blur(function () {
$("#lblinfo").html(" " + $(this).mask());
$("#TextBoxY").blur(function() {
$("#lblinfo2").html(" " + $(this).mask());
}).dblclick(function() {
$(this).unmask();
});
});
});
我如何获取代码来屏蔽用户输入的任何数字而不必是12号码?
示例:
如果用户有12个号码,他们将输入123,456,789,101,屏蔽将起作用。
如果用户有7个数字1,234,567,则掩蔽应该有效,但事实并非如此。如何让jQuery屏蔽任何数字?
How can I get the code to mask any number that the user enters without is having to be 12 numbers?
Example:
If user has 12 numbers they will enter 123,456,789,101 and the masking will work.
If a user has 7 numbers 1,234,567 the masking should work but it doesn't. How can I get the jQuery to mask any number?
推荐答案
( document )。ready( function (){
(document).ready(function () {
.mask.definitions [' 〜'] = [+ - ];
.mask.definitions['~'] = "[+-]";
( #TextBox1)。mask( 999,999,999,999);
("#TextBox1").mask("999,999,999,999");
这篇关于如何在jQuery中格式化掩码文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文