使用jQuery-plugin进行验证在AJAX调用后无效

时间:2012-10-07 03:09:00

标签: javascript jquery ajax jquery-plugins jquery-validate

我正在尝试使用jQuery-plugin验证表单。我在表格,国家,州和城市有三个常用的选择框。像往常一样,页面加载时会填充国家/地区选择框。使用Ajax在相应选择框的onchange事件中填充两个连续的选择框。

<div>
  <label> Country<span style="color: Red;">*</span></label>
  <select id="cmb_country" name="cmb_country" validation="required" class="inputText" onchange="fillState(this.value,0);">
    <option value=''>Select</option>
    <?php $combo->combo("select country_id, country_name from country", 0);?>
  </select>
</div>
<div class="clear"> </div>

<div>
  <label> State<span style="color: Red;">*</span></label>

  <span id="stateList">                         
      <select id="cmb_state" name="cmb_state" validation="required" class="inputText" onchange="fillCity(this.value, 0);">
        <option value=''>Select</option>                                                
      </select>
  </span>
</div>
<div class="clear"> </div>

<div>
  <label> City<span style="color: Red;">*</span></label>
  <span id="cityList">                          
      <select id="cmb_city" name="cmb_city" validation="required" class="inputText">
        <option value=''>Select</option>                                                
      </select>
  </span>
</div>
<div class="clear"> </div>

以下jQuery代码在Ajax调用之后总是返回false,阻止提交表单。

var Form = function(form) {

    var fields = [];

    form.find("[validation]").each(function() {
        var field = $(this);

        if (field.attr('validation') !== undefined) {
            fields.push(new Field(field));
        }
    });
    this.fields = fields;
}
Form.prototype = {
    validate: function() {

        for (field in this.fields) {

            this.fields[field].validate();
        }
    },
    isValid: function() {

        for (field in this.fields) {
            if (!this.fields[field].valid) {

                this.fields[field].field.focus();
                return false;
            }
        }
        return true;
    }
}

在不使用Ajax的情况下,使用Ajax填充所有选择框后如何使其工作正常?

0 个答案:

没有答案