使用 Jquery 进行页面定向
Page orientation with Jquery?
单击按钮时;如果页面上的所有文本框都不为空,它将定向到下一页。我使控件有效。但是我如何使用jquery定向到另一个页面呢?
$(document).on("pageinit", "#registerPage1", function () {
$(".nextBtn").click(function () {
if ($(".txt").val().lenght != 0) {
// i want to write codes for orientation registerPage1 to registerPage2 in here
}
$(".txt").each(function () {
if ($(this).val().length == 0 && $(this).next().attr('class') != 'nullInputMsg') {
($(this)).after('<div class="nullInputMsg">this field is required!</div>');
}
else if ($(this).val().length != 0 && $(this).next().attr('class') == 'nullInputMsg')
$(this).next().remove();
});
});
});
假设您有一个名为 myform
的表单,其中包含所有文本框。我们还假设带有类nextBtn
的按钮位于此窗体内,并触发窗体的提交行为。
像您所做的那样,在提交按钮的click
事件上验证表单是可以的。但是,只有在所有验证都通过时,您才希望移动到下一页,因此,您可能应该将重定向部分留到最后,届时您将确定验证检查的结果。在那之后,剩
- 将"myform"的操作属性设置为指向所需的页面。(它重定向到此页面) 如果验证
- 失败,则返回 false,如果验证从处理 click 事件的函数传递,则返回 true。
因此,您的代码看起来像
$(document).on("pageinit", "#registerPage1", function () {
$(".nextBtn").click(function () {
var validationPass = true;
$(".txt").each(function () {
if ($(this).val().length == 0 && $(this).next().attr('class') != 'nullInputMsg') {
($(this)).after('<div class="nullInputMsg">this field is required!</div>');
validationPass = false;
}
else if ($(this).val().length != 0 && $(this).next().attr('class') == 'nullInputMsg')
$(this).next().remove();
});
return validationPass;
});
});
你的 HTML 可能看起来像
....
....
<form id="myform" name="myform" action="RedirectToPage.php" method="get">
....
//form content housing the textboxes and button with class .nextBtn
....
</form>
....
....
我想你所说的方向是指重定向。你不需要jQuery进行重定向。简单的javascript就可以完成这项工作。
// works like the user clicks on a link
window.location.href = "http://google.com";
// works like the user receives an HTTP redirect
window.location.replace("http://google.com");
相关文章:
- jQuery使用anoSlide在手机上滑动
- jQuery使用api获取typeform结果
- JQuery使用相同的功能自动完成各种输入文本
- jQuery:使用“jQuery验证”后无法提交表单's远程验证
- jQuery使用ajax自动完成问题-TypeError:this.source不是函数
- jQuery:使用substr()的另一种方法
- 我如何让jQuery使用Greasemonkey 0.8脚本(在Firefox 2上),在没有互联网的情况下使用PC
- jquery使用name from变量按类选择元素
- JQuery:使用clone()生成的元素不采用原始的事件属性
- jQuery使用$.post上传文件
- 如何将数据附加到DOM元素以供jQuery使用
- jquery使用val()复制值似乎可以删除换行符
- jQuery使用.of()删除事件处理程序时出现的问题
- jquery使用输入框内容
- jQuery:使用实时事件添加tabindex属性
- Jquery使用html对象添加更多内容
- jQuery 使用 .scroll(handler) 滚动到元素
- PHP jQuery使用多个单词传递值
- 防止已选择的选项 Jquery 使用 MYSQL 自动完成
- jQuery使用XML数据更新UL列表