jquery验证插件在IE7中不起作用

时间:2013-12-11 02:23:12

标签: javascript jquery jquery-validate

我有一个表单页面。但是,表单页面在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;
    }       

});
});

1 个答案:

答案 0 :(得分:-1)

通过在

中添加按钮类型提交解决了该问题
button id="submit" name="submit" class="btn btn-primary center-block" title="SUBMIT ENTRY" type="submit">SUBMIT ENTRY</button>

对于IE7,需要添加按钮类型提交。我就知道。刚忘了这个时间。它已经解决了。