jQuery mobile: remember variable of page before

后端 未结 2 1358
野性不改
野性不改 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:06

    If this is a single page app, you could just switch the HREF of the setpage button when clicking the A and B buttons on the home page.

    Here is a DEMO

    $(document).on("pageinit", "#Home", function(){
        $('.btnAB').on("click", function(e){
            var id = $(this).prop("id");
            if (id === 'btnB'){
                $('#btnSetpage').prop('href', '#BBB');
            } else {
                $('#btnSetpage').prop('href', '#AAA');
            }
        });
    });
    

    The script above handles the click event of the 2 buttons (they have the same class). It sees which button was clicked and then sets the href of the one button on the setpage.

    Home

    A B

    setpage

    AAA

    I am AAA Home

    BBB

    I am BBB Home

提交回复
热议问题