How to pass and get Parameters between two Pages in Jquery Mobile?

前端 未结 5 385
天命终不由人
天命终不由人 2020-12-06 03:41

I am working on a some demo App to learn things in Jquery Mobile. I have tried a lot of options but not able to get solution on a few things :-

  1. http://jsfiddle
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-06 04:37

    I came up with this simple approach...

    First add custom HTML5 attributes to the elements on page 1 to hold the data to be passed. My attribute is named data-parm

       
    
    

    In your javascript, create a click handler (or other type of handler) that selects the attribute and assigns the value to a variable which will be available for you on page 2.

    For this example, I have added it to the html of a div that is on page 2.

    $("a").on("click", function (event) {
    
       var parm = $(this).attr("data-parm");
       //do something here with parameter on page 2 (or any page in the dom)
       $("#showParmHere").html(parm);
    
    });
    

提交回复
热议问题