我正在为表单使用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>
答案 0 :(得分: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>