2013-12-11 54 views
-1

我有一个表单页面。但是,表单页面不会在IE7中验证。我在控制台中看不到任何错误消息。它验证了所有其他浏览器...jQuery验证插件不能在IE7中工作

我的js代码低于

$(document).ready(function() { 

/* clear the form values when refreshed or reload*/ 
    function ClearForm() { 
    document.submitDetails.reset(); 
    } 
    $("input:not(':button, :submit, :reset, :hidden')").val('').checked = false; 
/*pretty chekable*/ 
    /*$('input.prettyCheckable').prettyCheckable({}); */ 

/*rulesets for validations*/ 
    var ruleSet1 = { 
    required: true, 
    maxlength: 120, 
    email: true 
    }; 
    var ruleSet2 = { 
    required: true, 
    maxlength: 80 
    }; 
    var ruleSet3 = { 
    required: true, 
    maxlength: 10, 
    minlength: 8, 
    number: true 
    }; 
    var ruleSet4 = { 
    required: true, 
    maxlength: 4, 
    minlength: 4, 
    number: true 
    }; 
    var ruleSet5 = { 
    required: true, 
    maxlength: 2, 
    minlength: 2, 
    number: true 
    }; 




$('#custom8').on('change', function() { 
    this.value = this.checked ? 1 : 0; 
}).change(); 
$('#custom9').on('change', function() { 
    this.value = this.checked ? 1 : 0; 
}).change(); 
$('#custom8').on('change', function(){ 
    $(this).valid() 
}) 
$('#custom9').on('change', function(){ 
    $(this).valid() 
}) 


    $('#submitDetails').validate({ 
/*if need to show error # message at top */ 
    /* showErrors: function(errorMap, errorList) { 
      $("#messageBox").html("This form contains " 
      + this.numberOfInvalids() 
      + " errors, see details below."); 
      this.defaultShowErrors(); 
      },*/ 
    // onfocusout: true, onkeyup: true, onclick:true, focusCleanup: true, 
    // 1. validation rules. 
    rules: { 
     firstName: ruleSet2, 
     lastName: ruleSet2, 
     address: ruleSet2, 
     suburb: ruleSet2, 
     state: { 
     required: true 
     }, 
     mobile: ruleSet3, 
     postCode: ruleSet4, 
     email: ruleSet1, 
     custom1: { 
     required: true 
     }, 
     custom2: { 
     required: true, 
     number: true, 
     min: 30 
     }, 
     custom3: { 
     required: true 
     }, 
     custom4: { 
     required: true 
     }, 
     custom5: { 
     required: true 
     }, 
     custom6: { 
     required: true, 
     maxlength: 2, 
     minlength: 2, 
     number: true, 
     min: 00, 
     max: 23 
     }, 
     custom7: { 
     required: true, 
     maxlength: 2, 
     minlength: 2, 
     number: true, 
     min: 00, 
     max: 60 
     }, 
     custom8:{ 
      required: true 
     } 
    },  
    groups: { 
     time: "custom6 custom7", 
     date: "custom3 custom4 custom5" 
    }, 
    errorPlacement: function (error, element) { 
     if (element.attr("name") == "custom2") 
     error.appendTo(".errorPurchase"); 
     else if ((element.attr("name") == "custom6") || (element.attr("name") == "custom7")) 
     error.appendTo(".errorTime"); 
     else if ((element.attr("name") == "custom8")) 
      error.appendTo("#error_msg");  
     else if ((element.attr("name") == "custom3") || (element.attr("name") == "custom4") || (element.attr("name") == "custom5")) 
     error.appendTo(".errorDate"); 
     else 
     error.insertAfter(element); 
    }, 
    messages: { 
     firstName: "Please enter your first name", 
     lastName: "Pleae enter your last name", 
     address: "Please enter your street address", 
     mobile: "Please enter valid 10 digit phone number (including area code for landline)", 
     postCode: "Please enter the 4 digits of your post code", 
     state: "Please select the store's state where you made your purchase", 
     email: "Please enter a valid email address", 
     custom2: "Total amount must be exact to the cent - minimum $30", 
     custom6: "Please enter the time (hours and minutes) found on your receipt in the format hh:mm. For example if 9:05am, please enter 09 in first field and 05 in second field.", 
     custom7: "Please enter the time (hours and minutes) found on your receipt in the format hh:mm. For example if 9:05am, please enter 09 in first field and 05 in second field.", 
     custom3: "Sorry, the date you have selected does not exist. Please check and try again", 
     custom4: "Sorry, the date you have selected does not exist. Please check and try again", 
     custom5: "Sorry, the date you have selected does not exist. Please check and try again", 
     suburb: "Please enter your town/suburb", 
     custom1: "Please select the store you made your purchase", 
     custom8: "You need to agree to participate in this competition" 
    } 
    }); 

///execute when submit button is clicked 
$("#submit").click(function() { 
    if (document.getElementById("custom8").checked) { 
     document.getElementById('custom8Hidden').disabled = true; 
    } 
    if (document.getElementById("custom9").checked) { 
     document.getElementById('custom9Hidden').disabled = true; 
    }  

}); 
}); 
+0

“onclick”,“onfocusout”和“onkeyup”选项**绝不能设置为“true”,因为这是默认操作,“true”会破坏内置函数。请参考文档进行自己的验证。 – Sparky

+0

它尚未设置为true。正如你可以看到,在js文件上的行已被注释掉 –

+0

只是重申它可以在除IE7以外的所有浏览器中工作 –

回答

-1

解决这个问题通过添加按钮式提交在

button id="submit" name="submit" class="btn btn-primary center-block" title="SUBMIT ENTRY" type="submit">SUBMIT ENTRY</button> 

对于IE7,需要添加按钮键入提交。我就知道。这次忘了。它已经解决了。

相关问题