1.新增html頁面。css
2.聲明html5Document。html
3.載入jQuery Mobile Css、jQuery與jQuery Mobile連接庫。html5
4.使用jQuery Mobile定義的html標準、編寫網頁架構及內容。jquery
向網頁中添加jQuery Mobile,添加方法以下:瀏覽器
從CDN引用jQuery Mobile(推薦) 架構
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"> <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
從jQuerymobile.com下載jQuery Mobile庫ide
從 jQuerymobile.com 下載文件。 工具
<link rel=stylesheet href=jquery.mobile-1.3.2.css> <script src=jquery.js></script> <script src=jquery.mobile-1.3.2.js></script>
在寫移動端的網站的時候, 必定要寫一個meta的name爲viewport的屬性, 由於該屬性表明着網站頁面的自適應。簡單的寫法爲:<meta name="viewport" content="width=device-width, initial-scale=1">表明着網站爲驅動設備的寬度。網站
代碼示例:spa
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"><!--自適應頁面--> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"> <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script> </head> <body> <div data-role="page" > <div data-role="header"> <h1>個人網站</h1> </div> <div data-role="content"> <p>這是正文部分</p> <ul data-role="listview"> <li data-role="list-divider">個人目標</li> <li><a href="http://www.baidu.com">精彩內容即將呈現</a></li> <li><a href="http://www.baidu.com">百度一下,就知道</a></li> <li><a href="http://www.baidu.com">堅持才能成功</a></li> </ul> </div> <div data-role="footer"> <h1>這個是頁腳文本</h1> </div> </div> </body> </html>
結果頁面: