如何创建一个jQuery验证,在点击按钮后提交页面重定向到另一个地址?
请给我一个例子,每个jQuery验证,(如:空字段(输入))
关于
为了重定向到另一个页面:
window.location.href = '/another-page';
就验证而言,我强烈建议您查看jquery验证插件。对于那些不想重新发明轮子的人来说,它是执行HTML表单的客户端验证的事实上的标准。
所以对于那些想要重新发明轮子的人,他们可以这样做:
$(function() {
$('#myform').submit(function() {
var myField = $('#myInput').val();
if (myField == '') {
alert('my field is required');
return false;
}
// at this stage we know tat the form is valid as the user
// filled the required myField. Now we can redirect
window.location.href = '/another-page';
return false;
});
});