여기에는 비어있는 경우 양식의 필드를 확인하는 함수가 있습니다. true 또는 false 인 경우 함수의 반환 값을 확인하는 방법
function ValidateForm()
{
jQuery('span.error_msg').hide();
var success = true;
jQuery("#shippingF input").each(function()
{
if(jQuery(this).val()=="")
{
jQuery(this).next().show();
success = false;
}
});
return success;
}
은 지금은 여기에 기능을 사용하고 싶었 :
function post(url,formId) {
jQuery("#process").html('<img src="<?php echo get_bloginfo('wpurl').'/wp-content/plugins/'.basename(dirname(__FILE__)).'/images/co/ajax-loader.gif'; ?>" alt="loading" title="ajax-loader" width="16" height="16" class="alignnone size-full wp-image-134">');
jQuery.post(url, jQuery('#' + formId).serialize(), function(d) {
jQuery('html,body').animate({scrollTop: jQuery("#scrollhere").offset().top},'slow');
jQuery("#response").html('<center><p style="height:820px"><span style="color:black;font-weight:bold;font: 11px arial,verdana,sans-serif;"><b>Loading available payment getaways..</b></span><br/><img src="<?php echo get_bloginfo('wpurl').'/wp-content/plugins/'.basename(dirname(__FILE__)).'/images/co/8-1.gif'; ?>" width="220" height="19" /></p></center>');
jQuery("#response").load("<?php echo get_bloginfo('wpurl').'/wp-content/plugins/'.basename(dirname(__FILE__)).'/checkout_payment.php'; ?>", function() { Cufon.refresh(); });
jQuery("#response").attr("style","height:1030px");
});
}
나는 그것을 시도하고 나는이 함께 제공됩니다.
function post(url,formId) {
ValidateForm();
if(ValidateForm() == 'false') {
jQuery('html,body').animate({scrollTop: jQuery("#shippingF").offset().top},'slow');
} else {
jQuery("#process").html('<img src="<?php echo get_bloginfo('wpurl').'/wp-content/plugins/'.basename(dirname(__FILE__)).'/images/co/ajax-loader.gif'; ?>" alt="loading" title="ajax-loader" width="16" height="16" class="alignnone size-full wp-image-134">');
jQuery.post(url, jQuery('#' + formId).serialize(), function(d) {
jQuery('html,body').animate({scrollTop: jQuery("#scrollhere").offset().top},'slow');
jQuery("#response").html('<center><p style="height:820px"><span style="color:black;font-weight:bold;font: 11px arial,verdana,sans-serif;"><b>Loading available payment getaways..</b></span><br/><img src="<?php echo get_bloginfo('wpurl').'/wp-content/plugins/'.basename(dirname(__FILE__)).'/images/co/8-1.gif'; ?>" width="220" height="19" /></p></center>');
jQuery("#response").load("<?php echo get_bloginfo('wpurl').'/wp-content/plugins/'.basename(dirname(__FILE__)).'/checkout_payment.php'; ?>", function() { Cufon.refresh(); });
jQuery("#response").attr("style","height:1030px");
});
}
}
문제는 검증 노력하고 있습니다 .. 그러나, .post()
기능은 빈 필드가 있음에도 불구하고 실행한다는 것입니다. 나는 if/else 조건에서 그것을 추측한다. 이것을 달성하기위한 더 좋은 방법이 있는가?
감사합니다.
ValidateForm을 두 번 호출하는 이유가 있습니까? –
문제는'Post()'함수에'ValidateForm();'을 포함하지 않으면 오류 메시지가 나타나지 않는다는 것입니다. – Ken
이미 if 내부에서 호출되고 있습니다. 그 전에 다시 전화 할 필요는 없습니다. –