您的位置:首页 > Web前端 > JQuery

使用jquery匹配正浮点数

2015-12-18 13:42 726 查看
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
</head>
<body>
<input type="text" class="text3-2-text">
<input type="submit" class="text3-2-submit">
</body>
</html>
<script>
var tes = $(".text3-2-text");
var btn = $(".text3-2-submit");
btn.click(function() {
var input = parseFloat(tes.val());
tes.val(input);
console.log(input);
var te = /^[0-9]+(\.[0-9]+)?$/;
if (!te.test(input)) {
tes.val('')
};
});
tes.keyup(function(e) {
var bb = tes.val();
var len = bb.length;
var leng = bb.replace(/\./g,'').length;
if (len - leng == 2) {
tes.val('')
};
var te = /^[0-9]+(\.[0-9]+)?$/;
if (e.keyCode == '110' || e.keyCode == '190') {

}
else{
if (!te.test(tes.val())) {
tes.val('')
};
};

});
</script>

本文出自 “IT技术” 博客,请务必保留此出处http://linuxubuntu.blog.51cto.com/4964714/1725993
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: