我正在尝试添加非必填字段但不确定如何添加多个字符串。添加一个很好但是当我添加多个时它会停止工作。谁能指出我可能缺少的东西?以下是代码;
jQuery( '#appointment-popup' ).on( 'click', 'input.submit-appointment', function() {
values = {
'name' : '',
'phone' : '',
'email' : '',
'appointment-date' : '',
'approximate-time' : '',
'place' : '',
'additional-notes' : '',
'solutions' : ''
};
areErrors = false;
jQuery.each( values, function( key, value ) {
currentElement = jQuery( '#appointment-form-in-popup form *[name='+ key +']' );
values[key] = currentElement.val();
if( key != 'additional-notes' ) { // put here unrequired fields
if( values[key] != false ) { currentElement.removeClass( 'error' ); }
else {
currentElement.addClass( 'error' );
areErrors = true;
}
}
});
if( areErrors == false ) {
// your action here, for example sending an email...
jQuery.ajax({
url: path_to_template +'/_assets/submit.php',
data: { 'submit': 'appointment-form', 'data': values, 'email': appointment_contact },
type: 'post',
success: function( output ) {
// animation after your action
jQuery.appointmentFormAnimation();
}
});
}
});
jQuery.appointmentFormAnimation = function() {
formHeight = jQuery( '.appointment-popup-content' ).height();
jQuery( '.appointment-popup-content' ).css({ 'minHeight' : formHeight });
jQuery( '#appointment-form-in-popup form' ).fadeOut( 300 );
setTimeout( function() {
jQuery( '#appointment-form-in-popup .thanks' ).fadeIn( 300 );
}, 400 );
}