0

单击按钮时;如果页面上的所有文本框都不是空的,它将指向下一页。我做了控制它的工作。但是我怎样才能用 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();
        });
    });

});
4

2 回答 2

0

我想你所说的方向是指重定向。您不需要 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");
于 2013-10-28T08:25:24.573 回答
0

假设您有一个名为myform容纳所有文本框的表单。让我们还假设带有类的按钮nextBtn在此表单内,并触发表单的提交行为。

就像您所做的那样,click在提交按钮的事件上验证表单很好。但是,只有在所有验证都通过时,您才希望移动到下一页,因此,您可能应该将重定向部分留到最后,通过您将在哪个时间确定验证检查的结果。在那之后,剩下要做的就是

  1. 设置“myform”的action属性指向需要的页面。(重定向到这个页面)
  2. 如果验证失败,则返回 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>
     ....
     ....
于 2013-10-28T08:29:35.047 回答