当前位置 : 主页 > 网页制作 > HTTP/TCP >

input 判断是否为正整数 并显示按钮或隐藏按钮

来源:互联网 收集:自由互联 发布时间:2021-06-16
form id= "subForm" style= " margin-top: 20 px ; " class= "layui-form" action= " %= path % /ap/ctrlApSetZetaParam?uid= ${ uid } " method= "post" div class= "layui-form-item" label class= "layui-form-label" 通信信道频点 /label div class
<form id="subForm" style="margin-top: 20px;" class="layui-form" action="<%=path%>/ap/ctrlApSetZetaParam?uid=${uid}" method="post">

<div class="layui-form-item">
<label class="layui-form-label">通信信道频点</label>
<div class="layui-input-inline">
<input onkeyup="this.value=this.value.replace(/[^0-9-]+.[^0-9-]+/);" oninput="OnInputMath (event)" onpropertychange="OnPropChangedMath (event)"
type="text" name="comFreq" style="width: 150px;" required lay-verify="required" placeholder="通信信道频点(1-15)" autocomplete="off" class="layui-input">
</div>
</div>

<div class="layui-form-item" style="align-content: center">
<div class="layui-input-block">
<div id="subBTN" type="reset" class="layui-btn layui-btn-normal" onclick="submitForm()">确认</div>
</div>
</div>
</form>

function OnInputMath (event) {
/*var reg=/^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$/;*/
var reg = /^[1-9]+[0-9]*]*$/;
if(event.target.value==""||reg.test(event.target.value)==true){
if (event.target.value >= 0 && event.target.value <= 15) {
document.getElementById("subBTN").style.display = ‘‘;
} else {
layer.msg("输入范围1~15");
document.getElementById("subBTN").style.display = ‘none‘;
}
} else {
layer.msg("请输入数字 ");
document.getElementById("subBTN").style.display = ‘none‘;
}
}
function OnPropChangedMath (event) {
if (event.propertyName.toLowerCase () == "value") {
/*var reg=/^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$/;*/
var reg = /^[1-9]+[0-9]*]*$/;
if(event.target.value==""||reg.test(event.target.value)==true){
if (event.target.value >= 0 && event.target.value <= 15) {
document.getElementById("subBTN").style.display = ‘‘;
} else {
layer.msg("输入范围1~15");
document.getElementById("subBTN").style.display = ‘none‘;
}
} else {
layer.msg("请输入数字 ");
document.getElementById("subBTN").style.display = ‘none‘;
} }}
网友评论