js 清除全部,验证空值,阻止提交

本文提供了一个JavaScript代码示例,用于在输入框为空时阻止提交,并改变边框颜色。

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

///clear value in textbox
function clearControlValueForm() {
$(':input:text').not(':button, :submit, :reset, :hidden')
.val('').removeAttr('selected').css("border", "");
}

///validate the empty value in textbox ,if has empty value ,prevent submit
$(document).ready(
function () {
$("input:submit").click(function () {
var isSubmit = true;
if (this.value != "Cancel" && this.value != "Previous") {
$("input:text").each(
function () {
if (this.value == "" && this.id.indexOf('Cat3') < 0 && this.id.indexOf('Cat4') < 0 && this.id.indexOf('Levels') < 0) {
this.style.border = "1px solid red";
isSubmit = false;
}
});
}
if (!isSubmit) {
// alert('Can not be null with "*"');
return isSubmit;
}
});
}
);

///monitor the value in textbox ,change the borderColor
$(document).ready(
function () {
$("input:text").change(
function () {
if (this.style.border == "1px solid red" && this.value != "") {
$(this).css("border", "")
}
}
)
}
);

新人,有问题请不惜赐教

转载于:https://www.cnblogs.com/fcq121/archive/2013/01/31/2886400.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值