我的聯繫表單和基於輸入字段的jQuery重定向有點問題。使用Javascript輸入字段值和重定向
一切都很完美,直到我試圖實現重定向以形成驗證碼。
重定向代碼:
$("#signup").submit(function(event){
window.location = $('input[type="radio"]:checked').val();
});
形式:
<form id="signup" name="signup" method="post" novalidate="novalidate">
<input type="radio" name="gender" value="http://www.paypal.com" checked> Option 1<br>
<input type="radio" name="gender" value="http://www.google.com"> Option 2<br>
<input type="radio" name="gender" value="http://www.seznam.cz"> Option 3<br>
<input id="submit" type="submit" name="submit" value="Continue to make payment..." class="btn btn-wide btn-extrawide" data-loading-text="Loading...">
的jQuery:
// Signup form
$('#signup').validate({
rules: {
name: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
}
},
messages: {
name: {
required: "Please enter your nameee",
minlength: "Your name must consist of at least 2 characters"
},
email: {
required: "Please enter your email address"
}
},
submitHandler: function(form) {
$(form).ajaxSubmit({
type:"POST",
data: $(form).serialize(),
url:"inc/signup.php",
success: function() {
$('#signup :input').attr('disabled', 'disabled');
$('#signup').fadeTo("slow", 0.15, function() {
$(this).find(':input').attr('disabled', 'disabled');
$(this).find('label').css('cursor','default');
$('#success').fadeIn();
});
// added lines, not working:
$("#signup").submit(function(event) {
window.location = $('input[type="radio"]:checked').val();
});
},
error: function() {
$('#signup').fadeTo("slow", 0.15, function() {
$('#error').fadeIn();
});
}
});
}
});
將竭誠爲您能給我任何反饋。萬分感謝。
亞當,這裏是什麼問題?請指定問題陳述 – ChiranjeeviIT
使用'window.location.href'而不是'window.location' – Jorrex
是的,使用'window.location.href'。 –