2017-05-25 38 views
-1

这是目前的形式:HTML形式屏蔽格式

<form> 
    Telephone: 
    <input type="text" name="telephone"> 
</form> 

我想设置屏蔽此输入,使其有一个面具一样xx-xx-xx

+0

https://css-tricks.com/input-masking/ –

+1

[如何实现带口罩的输入(HTTPS的可能重复://计算器。 com/questions/12578507/how-to-implement -a-mask-input- – Ray

回答

0

您可以在HTML中使用占位符。

<form> 
    Telephone: 
    <input type="text" name="telephone" placeholder="xx-xx-xx"> 
</form> 

然而,当用户开始输入,就会有占位符消失。

+0

它不起作用。您所说的占位符不会以屏幕上所需的格式显示值。我正在谈论掩码格式模式 –

1

你可以试试这个:

<html> 
<body> 
<head> 
<style> 
input { 
    font-family: monospace; 
} 
label { 
    display: block; 
} 
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; } 
</style> 
</head> 
<html> 
<body> 
<form action=""> 
    <div> 
    <label for="phn">Phone number</label> 
    <input id="phn" name="telephone" placeholder="XX - XX - XX" pattern="\w\d\w \d\w\d" class="masked" /> 
    </div> 

</form> 

<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/masking-input.js" data-autoinit="true"></script> 

</body> 
</html>