javascript - 更改输入类型月份的默认视图
问题描述
我正在使用 input[type='month'] 从用户那里获取到期日期。它通常看起来像这样:[![在此处输入图像描述][1]][1]
我想像这样向用户展示:[![在此处输入图像描述][2]][2]
这可以实现吗?
解决方案
这称为输入屏蔽。这是一个简单的代码,您可以使用它在没有 jQuery 或任何其他插件的情况下屏蔽输入。与其他插件相比,JS 文件占用的空间非常少。有关详细信息,请参阅此处。
input,input:hover,input:focus{
font-family: monospace;
border-width:0px;
border:none;
width:60px;
outline: none;
}
label {
display: inline;
}
div {
margin: 0 0 1rem 0;
}
.shell {
position: relative;
line-height: 1; }
.shell span {
position: absolute;
left: 3px;
top: 1px;
color: #ccc;
pointer-events: none;
z-index: -1; }
.shell span i {
font-style: normal;
/* any of these 3 will work */
color: transparent;
opacity: 0;
visibility: hidden; }
input.masked,
.shell span {
font-size: 16px;
font-family: monospace;
padding-right: 10px;
background-color: transparent;
text-transform: uppercase; }
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/masking-input.js" data-autoinit="true"></script>
<label for="cc">Expiry Date:</label>
<input id="cc" type="text" placeholder="MM/YY" class="masked" pattern="(1[0-2]|0[1-9])\/(1[5-9]|2\d)" data-valid-example="05/18"/>
推荐阅读
- visual-studio - 如何从 Windows 7 机器在 Visual Studio 2015 上安装和使用构建工具 v120 (2013)?
- django - Django 2 - 未找到视图的反向
- cordova - 如何通过 API 从 Cordova 上的移动应用程序从 Google Cloud Platform 获取数据?
- python - Python - 从图表和图例中删除边框
- javascript - 如何反转 CSS 过渡?
- python - 将 LetsEncrypt / Certbot 与 django 开发服务器一起使用?
- automation - 使用自动填充设置值进行静默安装
- php - Laravel 5.6 - 模型事件:你可以将 static::creating 和 static::updating 结合起来吗?
- swift - 从最后一项获取核心数据 ManageObject 排序
- java - 操作位于程序文件夹中的 SQLite 数据库