简体   繁体   中英

jquery mobile dialogs, passing values between pages

I want to make a popup ( page dialogs ) in jquery mobile with some input fields. How would i pass data from the popup to my main page?

And does the popup need to be a complete jquery ui page ( page anatomy ), or just a

<div data-role="page"> 
...
</div>

Thanks in advance!

Mobile page communication(passing data between pages) can be done in following ways:

  1. sessionStorage or localStorage of HTML5 Dom storage.
  2. global variables.
  3. jQuery.data()

Example for the usage of Jquery.data() is referred below.

http://dl.dropbox.com/u/49735179/dialog-data-transfer.html .

Hope this may help you :)

I haven't dug too far into jQuery mobile, but at a quick glance, it doesn't look much different than the popup dialogs from jQuery UI. In which case, you can try binding a data collector to a button in the initiation of the dialog.

$('#testdiv').dialog({ //initiate dialog
  someoption: "test", //fake stuff for example
  otheroption: "foo", // ---
  buttons: {  //define buttons for dialog
    "Ok": function() { //define "ok" button
      var userInput = $('#inputInDialog').val(); //get value of the textbox in the dialog
      $('#domOnMainPage').text(userInput); //write that value to main page
    }
  }
})

Again, I haven't got into mobile, but this is probably going to be pretty close to what you're looking for, I'm thinking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM