jQuery mobile: remember variable of page before

后端 未结 2 1357
野性不改
野性不改 2021-01-24 02:11

One button should redirect either to page AAA or to page BBB. This decision should depend on the choice of the buttons on the page before.

Page 1: #home

2条回答
  •  情歌与酒
    2021-01-24 03:07

    In addition to @ezanker's answer, you can retrieve all details related to the clicked button as well as previous and next pages on pagebeforechange event.

    $(document).on("pagebeforechange", function (event, data)
    

    Those details can be obtained from data object. For example, clicked / linked button details are retrieved from data.options.link object. previous page data.options.fromPage, and next page data.toPage.

    This event fires twice on transition, for the current page and the page it's moving to.

    $(document).on("pagebeforechange", function (e, data) {
      /* when webpage is first initialized, .link and .toPage are undefined */
      if (data.options.link && data.toPage) {
        if (data.toPage[0].id == "setpage") {
          var button = data.options.link[0].text;
          /* for demo */
          $("#setpage [data-role=content]").html("Clicked button: " + button);
        }
      }
    });
    

    Demo

提交回复
热议问题