JQuery脚本 - 看起来正确但不起作用

时间:2014-04-17 22:45:34

标签: jquery

我们有脚本用于确保填写订单上的必填字段。该脚本已经有效但现在不再有效了。不确定它是脚本还是页面中的其他元素。会喜欢一些输入 - 这是脚本:

<script type="text/javascript">
jQuery(window).load(function(){
jQuery('a.continueButton:first').unbind('click');    
jQuery("a.continueButton:first").click(function(event){    
var hollaback = jQuery(this).attr('href').replace(/javascript:/g, ''); 
event.preventDefault();  

if (jQuery("#Order0_PreviouslyAttended").val() == ''){    
alert("Please fill in your previous course details first"); 
jQuery("#Order0_PreviouslyAttended").focus();
return false;    

} else {    
if (jQuery("#Order0_DietaryNeeds").val() == ''){    
alert("Please let us know if you have any special dietary requirements"); 
jQuery("#Order0_DietaryNeeds").focus();
return false;

} else {    
if (jQuery("#Order0_Names").val() == ''){      
alert("Please select your preferred length of stay"); 
jQuery("#Order0_Names").focus();
return false;  

} else {    
if(jQuery('#agreement_checkbox').is(':checked')){
eval(hollaback);  
return true; 

} else {
alert("Please check the acknowledgement before proceeding");
jQuery("#agreement_checkbox").focus();
            }  
            }   
        }


});
jQuery(".paymentLabel:contains('Credit Card Type')").html('<b>Select Credit Card Type</b>');        //replace the text for Credit Card Type
});
</script>

1 个答案:

答案 0 :(得分:0)

格式化代码。你错过了一些卷发。

jQuery(window).load(function(){
jQuery('a.continueButton:first').unbind('click');    
jQuery("a.continueButton:first").click(function(event){    
    var hollaback = jQuery(this).attr('href').replace(/javascript:/g, ''); 
    event.preventDefault();  

    if (jQuery("#Order0_PreviouslyAttended").val() == '')
    {    
        alert("Please fill in your previous course details first"); 
        jQuery("#Order0_PreviouslyAttended").focus();
        return false;    

    } 
    else 
    {    
        if (jQuery("#Order0_DietaryNeeds").val() == '')
        {    
            alert("Please let us know if you have any special dietary requirements"); 
            jQuery("#Order0_DietaryNeeds").focus();
            return false;
        }
        else 
        {    
            if (jQuery("#Order0_Names").val() == '')
            {      
                alert("Please select your preferred length of stay"); 
                jQuery("#Order0_Names").focus();
                return false;  
            } 
            else 
            {    
                if(jQuery('#agreement_checkbox').is(':checked'))
                {
                    eval(hollaback);  
                    return true; 
                } 
                else 
                {
                    alert("Please check the acknowledgement before proceeding");
                    jQuery("#agreement_checkbox").focus();
                }  
            }   
         }
    }


    });
    jQuery(".paymentLabel:contains('Credit Card Type')").html('<b>Select Credit Card Type</b>');        //replace the text for Credit Card Type
});

我对这种结构有一些疑虑,你知道&#34;替换信用卡类型的文本&#34;这是正确格式化后的事件。你应该重新考虑你想要完成的事情以及你如何去做。