电话号码的jQuery输入掩码 [英] jQuery input mask for phone number

查看:38
本文介绍了电话号码的jQuery输入掩码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户的输入自动填充电话号码的标点符号,以便看起来像这样 (xxx) xxx-xxxx.这是我的 HTML 代码:

 

<label class="control-label col-sm-2">电话号码:</label><div class="col-sm-10"><input type="text" class="form-control" name="phoneNumber"id="phoneNumber" value="<?php echo $row["phoneNumber"];?>">

我还需要做什么才能完成这项任务?我正在尝试使用 jQuery 和输入掩码.

解决方案

您可以使用 Input Mask jQuery 扩展来完成此操作.

$('#phoneNumber').inputmask("(999) 999-9999");

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script><label class="control-label col-sm-2">电话号码:</label><div class="col-sm-10"><input type="text" class="form-control" name="phoneNumber" id="phoneNumber" value="">

I want a user's input to autofill the punctuation of a phone number in order to look like this (xxx) xxx-xxxx. This is my HTML code:

  <div class="form-group">
    <label class="control-label col-sm-2">Phone Number:</label>
    <div class="col-sm-10">          
      <input type="text" class="form-control" name="phoneNumber"
           id="phoneNumber" value="<?php echo $row["phoneNumber"];?>">
    </div>
  </div>

What else do I need to do to complete this task? I am trying to use jQuery and an input mask.

解决方案

You can accomplish this by using the Input Mask jQuery extension.

$('#phoneNumber').inputmask("(999) 999-9999");

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>

<label class="control-label col-sm-2">Phone Number:</label>
  <div class="col-sm-10">          
  <input type="text" class="form-control" name="phoneNumber" id="phoneNumber" value="">
</div>

这篇关于电话号码的jQuery输入掩码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆