javaScript 确认验证框
<script type="text/javaScript">
function deleteitem() {
var b = window.confirm("你确认归零吗?");
if (b) {
//window.location.href = "#"
window.location.reload();
//window.location.href = "${pageContext.request.contextPath}/servlet地址"
}
}
function changeQuantity(input){
var quantity = input.value;
var oldvalue = document.getElementById("oldvalue");
if(quantity!=parseInt(quantity) || quantity <0){
alert("请输入正整数!!");
input.value = oldvalue.value;
return;
}
oldvalue.value = input.value;
//window.location.href = "${pageContext.request.contextPath}/servlet地址"
alert("修改成功");
}
</script>
</head>
<body>
<input type="text" value="0" hidden="hidden" id="oldvalue">
<input id="test" type="text" value="0" onchange="changeQuantity(this)">
<a href="javascript:void(0)" onclick="deleteitem()">归零</a>
</body>
本文介绍了一个使用JavaScript实现的确认对话框及输入验证的功能。通过`window.confirm`进行删除确认提示,利用`window.location.reload`刷新页面;并通过`changeQuantity`函数验证输入框中的数值是否为正整数,并在修改成功后给出提示。
958

被折叠的 条评论
为什么被折叠?



