单击按钮时;如果所有文本框都不是空的,则将指向下一页。我控制它起作用了。但是,如何使用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();
});
});
});发布于 2013-10-28 08:29:35
让我们假设您有一个名为myform的表单,它包含所有文本框。我们还假设类nextBtn的按钮在此表单中,并触发表单的提交行为。
正如您所做的那样,在submit按钮的click事件上验证表单是fine.However,只有当所有验证都通过时,您才希望移动到下一页,因此,您可能应该将重定向部分保留到最后,届时您将确定验证检查的结果。在那之后,剩下的就是
所以,您的代码看起来就像
$(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>
....
....发布于 2013-10-28 08:25:24
我想你所说的定向是指重定向。您不需要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");https://stackoverflow.com/questions/19629728
复制相似问题