我有一个函数,循环通过我的表单的所有输入,并检查它们是否填充。如果该字段为空,则会使该特定输入变成粉红色并返回false。错误消息不显示和隐藏取决于如果else语句
我试图在没有填充的输入下面添加一个“Field Required”消息。所以我编写了一个额外的表格后,每一个行,与保存错误信息的股利。在加载页面时,div的css设置为“display:none”。
现在我的功能正在为每个输入显示“必需”,而不仅仅是空白的,但粉色仍然正常工作。
我如何获得“必需”的div来正确显示和隐藏粉红色的颜色?
checkinputs = function (blockOne,blockTwo) {
inputGood = true;
blOne = $(blockOne);
blTwo = $(blockTwo);
blInput = [blOne,blTwo];
for (x = 0; x < 2; x++) {
var validators = blInput[x].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) {
$(this).css('background-color', 'white');
$(this).closest('div').find('.required').hide();
$(this).parent('td').prev('td').find('span').text('*');
}
else {
$(this).css('background-color', 'pink');
$(this).closest('div').find('.required').show();
$(this).parent('td').prev('td').find('span').text('*');
inputGood = false;
}
return isFilled;
}).length;
var inputCount = validators.length;
};
if(!inputGood){
$('#errorAlert').append('<span style="font-weight:bold;">"Some required information is missing. Please complete the missing fields below."</span>' + '<br><br>');
$('#errorAlertTwo').append('<span style="font-weight:bold;">"Some required credit card information is missing. Please complete the missing fields below."</span>' + '<br><br>');
}
return inputGood;
};
这里是问题的小提琴: http://jsfiddle.net/RNMM7/
请显示您的html标记,也显示完整的js代码,$(this)指的是什么? – Huangism 2013-05-01 15:19:45
如果你可以做一个小提琴,它会更好! – 2013-05-01 15:20:08
没有HTML,这个JavaScript代码是没有意义的。也张贴您的HTML – Ejaz 2013-05-01 15:23:03