0

我已经更新了这篇文章。我已经确定问题出在 jquery validate 中,但不知道如何纠正它。我有以下代码来验证注册表单。在 Firefox、Chrome 或 IE9 中,如果用户尝试单击空白表单上的注册按钮,则错误消息会正常显示。在 IE7 或 8 中不会出现错误消息。

这是jQuery:

$('#form_register').validate({
messages: {
register_full_name: 'Please enter your name',
register_email: {
required: 'Please enter your email',
email: 'Please enter a valid email address'
},
register_username: {
  required: 'Please choose a username',
  minlength: 'Make it at least 3 characters'
  },
register_password: {
  required: 'Please choose a password',
  minlength: 'Make it at least 6 characters'
   },
register_newsletter: {
  required: 'Please select either Yes or No'
   }
 },
rules: {
  register_password: {
    required: true,
    minlength: 6
  },
  register_username: {
    minlength: 3
    }
   },
  submitHandler: function(){
   submit_register();
   return false;
   }
});

此警报不会在 IE7 或 IE8 中显示:

$.validator.setDefaults({
  errorElement: 'span',
  errorPlacement: function(error, element){
    alert('$.validator.setDefaults');
    $(element.parent('label')).addClass('error');
    error.appendTo( element.parent('label') );
    },
    success: function(label){
    $(label.parent('label')).removeClass('error');
    }
});

表单位于 PHP 文档中:

        <div class="fb-login-button"><?php _e('Connect with Facebook'); ?></div>
        <p class="or"><span class="left"></span><?php _e('or'); ?><span class="right"></span></p>
        <span class="error server"></span>
        <form id="form_register" class="dialog-field" name="form_register" action="<?php bloginfo('url'); ?>/register" method="post" accept-charset="UTF-8">
            <input id="register_nonce" name="register_nonce" type="hidden" value="<?php echo wp_create_nonce( 'register_nonce' ) ?>" />
            <input type="hidden" name="action" value="ic_submit_register" />
            <fieldset class="width4">
                <label class="width2 first hide"><?php _e('Username'); ?>
                    <input id="register_username" name="register_username" type="text" class="text required" value="" placeholder="Username for comments, lookbook" />
                    <p class="note"><?php _e('3 or more alphanumeric characters.'); ?></p>
                </label>
                <div class="clear"></div>
                <label class="width2 first hide"><?php _e('Email'); ?>
                    <input id="register_email" name="register_email" type="text" class="text required email" placeholder="Email Address" value="" />
                </label>
                <div class="clear"></div>
                <label class="width2 first hide"><?php _e('Password'); ?>
                    <input id="register_password" name="register_password" type="password" class="text" data-typetoggle="#register_showme" placeholder="Password" />
                    <p class="note"><?php _e('6 or more alphanumeric characters.'); ?></p>
                </label>
                <label id="showme" class="width2 first">
                    <input id="register_showme" name="register_showme" type="checkbox" /><?php _e('show me'); ?>
                </label>
                <div class="clear"></div>
                <fieldset class="width2 radio">
                    <div class="toggle">
                        <label class="radio">
                            <span><?php _e('Yes'); ?></span>
                            <input type="radio" name="register_newsletter" value="1" class="required">
                        </label>
                        <label class="radio">
                            <span><?php _e('No'); ?></span>
                            <input type="radio" name="register_newsletter" value="0">
                        </label>
                    </div>
                </fieldset>
                <div class="clear"></div>
            </fieldset>
4

1 回答 1

0

这可能无法解决问题,但您的情况看起来很糟糕:

if(res!==null || res!=="" || res!=="Username for comments, lookbook")

我想你想要

if(res!==null && res!=="" && res!=="Username for comments, lookbook")

因为

res !== null or res !== ""

将始终评估为真。

于 2012-08-20T17:32:05.250 回答