我有一个下拉菜单,其中包含必需、选项等条件,并且隐藏了大约 8 个文本字段。即使字段被隐藏,也很少有字段得到验证并抛出错误消息。如何避免这种情况?请帮助解决这个问题。
我的代码是:
function responseFunction(res) {
//1:mandatory
//2:optional
//3:hidden
var str = res.split("~");
for (i in str)
{
var field= str[i].split(':');
switch (field[0]) {
case "BillingAddressLine1":
switch (field[1]) {
case "1":$('#ContentSection_lblBillingInfoAddress').prepend('<span>*</span>');
$("#<%= txtBillingInfoAddress.ClientID %>").rules("add", {required : true, messages : {
required : 'Please Enter Address' }});
break;
case "3":$('#ContentSection_lblBillingInfoAddress, #ContentSection_txtBillingInfoAddress').hide().parent('p').css("paddingTop", "0px");
break;
}
break;
case "BillingFullName":
switch (field[1]) {
case "1":$('#ContentSection_lblBillingInfoAccountHolderName').prepend('<span>*</span>');
$("#<%= txtBillingInfoAccountHolderName.ClientID %>").rules("add", {required : true, messages : {
required : 'Please Enter Account Holder Name' }});
break;
case "3":$('#ContentSection_lblBillingInfoAccountHolderName, #ContentSection_txtBillingInfoAccountHolderName').hide().parent('p').css("paddingTop", "0px");
break;
}
break;
}
}
我的截图是: https ://www.dropbox.com/sh/asmpnuiqqlo40us/S9yHCuNSyl?m#f:errorThrowing.jpg