文本框中禁止非数字字符输入比如手机号码、邮编

时间:2013-08-19    点击:101   
在工作中,总是遇到很多禁止非数字字符输入的文本框,比如手机号码了 邮编了
复制代码 代码如下:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="style.css">
</head>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<body>
<input type="text" id="phone" value="0000">
</body>
<script type="text/javascript">
jQuery(document).ready(function($) {
// Stuff to do as soon as the DOM is ready;
var phone=$('#phone');
$(phone).on('click',function(){
phone.val('');
})
$(phone).on('keyup',function(evt){
var phoneVal=phone.val();
phoneVal=phoneVal.replace('/[^\d]+/g', ''); //替换非数字字符为空格
phoneVal=parseInt(phoneVal,10);
if(isNaN(phoneVal)){
phoneVal = '';
}
this.value=phoneVal;
})
});
</script>
</html>
jquery indexOf使用方法
js里取容器大小、定位、距离等属性搜集整理
没有document.getElementByName方法
js中符号转意问题示例探讨
JavaScript异步编程:异步数据收集的具体方法
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved