使用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
<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
相关文章推荐
- Jquery中使用setInterval和setTimeout
- jquery获取css的color值返回RGB的方法
- jquery简单倒计时实现方法
- jquery中object对象循环遍历的方法
- 【jQuery】利用lazyload.js延迟加载技术应对多图杀猫的单一页面
- 基于jQuery动态创建html元素
- HTML5+jquery整屏页面切换效果
- jquery中ajax跨域方法实例分析
- 使用<script>和HTML5<template>作为模板元素的差别:能否使用jQuery选中
- 解决jQuery上传插件Uploadify出现Http Error 302错误的方法
- jquery改变链接移上光标时的颜色实例
- jQuery validate在没有校验通过的情况下拒绝提交
- jQuery Validate表单验证深入学习
- jquery模仿css3延迟效果
- Jquery 中 ajaxSubmit使用讲解
- jQuery Validate表单验证入门学习
- jQuery定义插件的方法
- JQueryMobile+融云webSDK创建的聊天室有多余空白
- jquery控制导航定位,浮动窗跟随网页变化
- jquery中判断是否按下回车enter键