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

///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", "")
}
}
)
}
);

新人,有问题请不惜赐教

posted @ 2013-01-31 09:39  ^_^哈哈  阅读(304)  评论(0编辑  收藏  举报