本文實例講述了jQueryMobile窗體長內容的缺陷與解決方法。分享給大家供大家參考,具體如下:
前面的一篇文章《jQueryMobile之Helloworld與頁面切換的方法》沒有考慮到窗體中放置長內容的狀況
一旦窗體中出現長內容,使用筆者那種固定header與footer的全屏布局是存在缺陷的,

如圖所示,長內容最后的內容,直到滾動條拉到最底部也無法窮盡,
而且很有可能的是,雖然現在這個地方的內容是顯示為半透明,但往往這個位置是一些提交按鈕什么的,
用戶根本就沒法點,
因此,需要進行改進,把原來的代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>a</title><meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"><link rel="stylesheet" href="jqmobile/jquery.mobile-1.4.5.css" rel="external nofollow" rel="external nofollow" ><script src="jqmobile/jquery-1.11.1.js"></script><script src="jqmobile/jquery.mobile-1.4.5.js"></script></head><body><div data-role="page" data-position="fixed" data-fullscreen="true"> <div data-role="header" data-theme="b" data-tap-toggle = "false"> <h1>title</h1> </div> <div data-role="content"> <p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p> </div> <div data-role="footer" data-position="fixed" data-fullscreen="true" data-theme="b" data-tap-toggle = "false"> <div data-role="navbar"> <ul> <li><a href="a.html" rel="external nofollow" rel="external nofollow" target="_self" data-icon="info">a</a></li> <li><a href="b.html" rel="external nofollow" rel="external nofollow" target="_self" data-icon="grid">b</a></li> <li><a href="#" rel="external nofollow" rel="external nofollow" class="ui-btn-active ui-state-persist" data-icon="star">c</a></li> </ul> </div> </div></div></body></html>
之中的content圖層加上樣式,style="margin-bottom:50px"也就是變成:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>a</title><meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"><link rel="stylesheet" href="jqmobile/jquery.mobile-1.4.5.css" rel="external nofollow" rel="external nofollow" ><script src="jqmobile/jquery-1.11.1.js"></script><script src="jqmobile/jquery.mobile-1.4.5.js"></script></head><body><div data-role="page" data-position="fixed" data-fullscreen="true"> <div data-role="header" data-theme="b" data-tap-toggle = "false"> <h1>title</h1> </div> <div data-role="content" style="margin-bottom:50px"> <p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p><p>本頁還在建設中</p> </div> <div data-role="footer" data-position="fixed" data-fullscreen="true" data-theme="b" data-tap-toggle = "false"> <div data-role="navbar"> <ul> <li><a href="a.html" rel="external nofollow" rel="external nofollow" target="_self" data-icon="info">a</a></li> <li><a href="b.html" rel="external nofollow" rel="external nofollow" target="_self" data-icon="grid">b</a></li> <li><a href="#" rel="external nofollow" rel="external nofollow" class="ui-btn-active ui-state-persist" data-icon="star">c</a></li> </ul> </div> </div></div></body></html>
則可以窮盡頁面了,如下圖所示:

更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結》、《jQuery擴展技巧總結》、《jQuery切換特效與技巧總結》、《jQuery遍歷算法與技巧總結》、《jQuery常見經典特效匯總》、《jQuery動畫與特效用法總結》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答