100以内小数保留一位 动态校验

本文介绍了一个简单的JavaScript程序,用于验证输入字段中的数值是否为100以内的小数,并保留一位小数点。该程序通过正则表达式进行匹配检查,实时反馈验证结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<html>
<head>
<title>100以内小数保留一位</title>
<script src="js/jquery1.9.js" type="text/javascript"></script>
</head>
<body>
<input id="c" type="text" value="" /><input id="d" type=text value="" style='background-color:rgb(241, 239, 238);outline:none;border:none;display:none;color:red; ' />


<script type="text/javascript">
jQuery("#c").keyup(function() {
confirmdata("c","--");
});


function confirmdata(confirmid,whichone){


var ex = /^(100|[1-9]?\d(\.\d))$/; 
var vl = document.getElementById(confirmid).value;
var x = ex.test(vl);
var r = x?"匹配":"不匹配";
   
if(vl=='100'){
r = '不匹配';
jQuery("#"+confirmid+"").css({
"color" : "#ff0000"
});
jQuery("#"+confirmid+"").attr("name","unpass");
jQuery("#d").show();
jQuery("#d").val(whichone +"不匹配");
}
if(r == '不匹配'){
jQuery("#"+confirmid+"").css({
"color" : "#ff0000"
});
jQuery("#"+confirmid+"").attr("name","unpass");
jQuery("#d").show();
jQuery("#d").val(whichone +"不匹配");

}else if(r =='匹配'){
jQuery("#"+confirmid+"").css({
"color" : "#000000"
});
jQuery("#"+confirmid+"").attr("name","pass");
jQuery("#d").val(whichone +"匹配");
jQuery("#d").hide();
}
if(vl=='0'){
    jQuery("#"+confirmid+"").css({
"color" : "#000000"
});
jQuery("#"+confirmid+"").attr("name","pass");
jQuery("#d").val(whichone +"匹配");
jQuery("#d").hide();
   }
}








</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值