2

我正在为我的表单使用 jquery 表单向导,它是一个多页表单,示例如下: http ://thecodemine.org/examples/example_1_straight.html

该表单使用 jquery 验证插件,在jquery.validation.js中,没有密码验证规则或检查重新输入密码。

我尝试了许多其他简单的验证表单代码,但它们不适用于表单向导,可能是因为这是多页表单,当我单击下一步按钮时它没有传递信息

如果我使用 mootools 进行验证,则 jquery 表单向导停止工作。

我正在尝试使用小定制后提到的简单代码,但它也不适用于表单,但它适用于其他简单表单。

请指导我如何在我的页面中使用此脚本,这与上述链接中的示例完全相同。

首先我调用将值传递给表单向导来创建动画表单,下面提到的代码

   <script type="text/javascript">
        $(function(){
            $("#SignupForm").formwizard({ 
                formPluginEnabled: true,
                validationEnabled: true,
                focusFirstInput : true,
                formOptions :{
                    success: function(data){$("#status").fadeTo(500,1,function(){ $(this).html("You are now registered!").fadeTo(5000, 0); })},
                    beforeSubmit: function(data){$("#data").html("data sent to the server: " + $.param(data));},
                    dataType: 'json',
                    resetForm: true
                }   
             }
            );
    });
</script>

以下是我尝试在表单中使用的验证码,但它不起作用

     <script type="text/javascript">
$(function(){

var pass1 = $('#password'),
    pass2 = $('#passwordConfirm'),
    email = $('#email'),
    form = $('#SignupForm'),
    strength = $('#strength'),
    arrow = $('#form-div .arrow');

// Empty the fields on load
$('#main .row input').val('');

// Handle form submissions
form.on('submit',function(e){

    // Is everything entered correctly?
    if($('#main .row.success').length == $('#main .row').length){

        // Yes!
        alert("Thank you for trying out this demo!");
        e.preventDefault(); // Remove this to allow actual submission

    }
    else{

        // No. Prevent form submission
        e.preventDefault();

    }
});

// Validate the email field
email.on('blur',function(){

    // Very simple validation
    if (!/^\S+@\S+\.\S+$/.test(email.val())){
        email.parent().addClass('error').removeClass('success');
    }
    else{
        email.parent().removeClass('error').addClass('success');
    }

});

// Use the complexify plugin on the first password field
pass1.complexify({minimumChars:7, strengthScaleFactor:0.4}, function(valid, complexity){

    if(valid){
        pass2.removeAttr('disabled');

        pass1.parent()
                .removeClass('error')
                .addClass('success');
    }
    else{
        pass2.attr('disabled','true');

        pass1.parent()
                .removeClass('success')
                .addClass('error');
    }



    var calculated = (complexity/100)*268-30;
    if(calculated <50){
    $('#strength').text('Very Weak');

    strength.removeClass('GreenJoy').addClass('RedWarn');

    }

    if(calculated >50 && calculated < 100){
    $('#strength').text('Weak');

    strength.removeClass('GreenJoy').addClass('RedWarn');

    }

    if(calculated >100 && calculated < 150){
    $('#strength').text('Normal');

    strength.removeClass('RedWarn').addClass('GreenJoy');

    }

    if(calculated >170 && calculated < 200){
    $('#strength').text('Good');

    strength.removeClass('RedWarn').addClass('GreenJoy');
    }

    if(calculated >235){
    $('#strength').text('Perfect!');

    strength.removeClass('RedWarn').addClass('GreenJoy');
    }


});

// Validate the second password field
pass2.on('keydown input',function(){

    // Make sure its value equals the first's
    if(pass2.val() == pass1.val()){

        pass2.parent()
                .removeClass('error')
                .addClass('success');
    }
    else{
        pass2.parent()
                .removeClass('success')
                .addClass('error');
    } 
});

 });

</script>
4

1 回答 1

1

我得到了它:)

jquery.validate.js中有一个验证规则equalTo

我这样做是为了获得密码验证

HTML

   <label for="password">Password</label>
<label for="password" id="strength" style="font-weight:normal"></label>
<input class="ui-wizard-content ui-helper-reset ui-state-default" disabled="disabled" name="password" id="password" type="password">

<label for="passwordConfirm">Retype password</label>

<input class="ui-wizard-content ui-helper-reset ui-state-default equalTo required" disabled="disabled" name="passwordConfirm" id="passwordConfirm" type="password">

JavaScript

  <script>
 $(document).ready(function(){
 $("#SignupForm").validate({
 rules: {
password: "required",
passwordConfirm: {
  equalTo: "#password"
}
}
});
 });
 </script>
于 2012-11-16T22:44:55.613 回答