Phone:<br>
<input type="text" id="phone" name="phone" placeholder="Please enter your phone number">
The input box looks like this to begin with
On click/focus, it looks like this
在键入数字时,应替换下划线,或者应在下划线上键入数字
我试过像这样的东西-
<input type="text" name="theName" placeholder="Please enter your phone number"
onblur="if(this.placeholder!==''){ this.value='Please enter your phone number'; this.style.color='#BBB';}"
onfocus="if(this.placeholder=='Please enter your phone number'){ this.value='___-___-____'; this.style.color='#000';}"
style="color:#BBB;" />
但当我开始输入电话号码时,我想让它在下划线上输入,而不是像现在这样。
发布于 2017-08-12 05:11:28
插入这两个Jquery插件-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.js"></script>
HTML的其余部分包含以下Jquery函数和简单的电话号码输入框-
<script>
$(document).ready(function($){
$('#phone').mask('999-999-9999', {placeholder:'xxx-xxx-xxxx'});
});
</script>
</head>
<body>
<form action="">
<input type='text' name='phone' id='phone' placeholder='enter phone no.'>
</form>
</body>
https://stackoverflow.com/questions/45624568
复制相似问题