首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Jquery定位页面?

问用Jquery定位页面?
EN

Stack Overflow用户
提问于 2013-10-28 08:05:11
回答 2查看 83关注 0票数 0

单击按钮时;如果所有文本框都不是空的,则将指向下一页。我控制它起作用了。但是,如何使用jquery定位到另一个页面呢?

代码语言:javascript
复制
$(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();
        });
    });

});
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-28 08:29:35

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

正如您所做的那样,在submit按钮的click事件上验证表单是fine.However,只有当所有验证都通过时,您才希望移动到下一页,因此,您可能应该将重定向部分保留到最后,届时您将确定验证检查的结果。在那之后,剩下的就是

  1. 将'myform`‘的action属性设置为指向所需的页面。(它将重定向到此页面)
  2. 如果验证失败,则返回false;如果从处理单击事件的函数传递,则返回true。

所以,您的代码看起来就像

代码语言:javascript
复制
    $(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应该看起来像

代码语言:javascript
复制
     ....
     ....
      <form id="myform" name="myform" action="RedirectToPage.php" method="get">
        ....
        //form content housing the textboxes and button with class .nextBtn
        ....
      </form>
     ....
     ....
票数 0
EN

Stack Overflow用户

发布于 2013-10-28 08:25:24

我想你所说的定向是指重定向。您不需要jQuery来重定向。简单的javascript将完成这项工作。

代码语言: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");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19629728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档