多的不说,直接上代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>手机号空格填充</title>
<script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
function getMoblieFormat(obj)
{
var value = obj.value;
value = value.replace(/\s*/g, "");
var result = [];
for(var i = 0; i < value.length; i++){
if (i==3||i==7){
// console.log(value.charAt(i));
result.push(" " + value.charAt(i));
}else{
result.push(value.charAt(i));
}
}
obj.value = result.join("");
}
</script>
</head>
<body>
手机号:
<input type="text" id="tel" value="" placeholder="请输入手机号。。。" onkeyup="getMoblieFormat(this)" maxlength="13" />
</body>
</html>
【精选秒杀】热卖云产品限量抢,云服务器20元/月起,服务稳定,价格更优
https://cloud.tencent.com/redirect.php?redirect=1039&cps_key=8ee0f9c89dfe0958071ea9b77e110670&from=console
淘宝优惠券: http://tq.xinrtd.com
京东优惠券: http://jp.xinrtd.com