checkinputs = function (block) {
var notAllFilled = $(block).find('input').filter(function () {
return $.trim(this.value) === "";
});
var alertText = notAllFilled ? "form is still missing input" : "form has been filled";
alert(alertText);
}
$('body').on("click", "#step_3", function (e) {
checkinputs('#ctl00_MainContentHolder_StoreAddressEditorBilling_addressDiv');
});
编辑:更新了一个非常详细的版本。检查隐藏的输入并忽略它们。给出好的石灰背景和坏的浅绿色,并用粉红色的父背景显示它正在验证的那些。
还根据有效性调整“*”文本。
这完全取决于博客中元素的 id 结尾。
您需要清理它以进行生产!
checkinputs = function (block) {
var validators = $(block).find("[id$='RequiredIndicator']").parent().parent('tr').find(':input:not(:hidden)');
var notAllFilled = validators.filter(function () {
var myInput = $(this); //.parent().parent('tr').find(':input');
var filledVal = myInput.val();
var isFilled = $.trim(filledVal).length;
if (isFilled) {
myInput.css('background-color', 'lime');
$(this).parent('td').prev('td').find('span').text(' ');
} else {
myInput.css('background-color', 'aqua');
$(this).parent('td').prev('td').find('span').text('*');
}
return isFilled;
}).length;
validators.parent().css('background-color', 'pink');
var inputCount = validators.length;
var alertText = notAllFilled == inputCount ? "form has been filled" : "form is still missing input";
alert(alertText);
};
$('body').on("click", "#step_3", function (e) {
checkinputs('#ctl00_MainContentHolder_StoreAddressEditorBilling_addressDiv');
});