Jan 172013
Come in jQuery c’è la possibilità di andare a gestire (leggere, scrivere, rimuovere) i contenuti degli attributi data-, la stessa cosa possiamo farla con jQuery Mobile. La variante sostanziale è ne metodo da utilizzare: jqmData().
Il codice:
<!DOCTYPE html> <html> <head> <title>Page Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css"> <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script> <script> $(document).ready(function(e) { $('#set-data').on('click',function(e){ $('#store').jqmData('chiave','Contenuto inserito'); }) $('#get-data').on('click',function(e){ alert($('#store').jqmData('chiave')) }) }); </script> </head> <body> <div data-role="page" id="pagina"> <div data-role="header"><h1>JQMData</h1></div> <div data-role="content"> <p id="store">Paragrafo contenitore</p> <a href="#" id="set-data" data-role="button">Set data</a> <a href="#" id="get-data" data-role="button">Get data</a> </div> </div> </body> </html>
Come si può vedere abbiamo due bottoni, uno per scrivere e uno per leggere, al document ready associamo il click e in base al click andiamoa scrivere/leggere nel paragrafo che nel nostro caso fa da contenitore
L’esempio
Google+
Sorry, the comment form is closed at this time.