你需要了解的 10 个 jQuery mobile 贴士和代码片段

1. 一个完整的基本页面
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Page Title</title>
  5. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
  6. <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
  7. <script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
  8. </head>
  9. <body>
  10. <div data-role="page" id="home">
  11. <div data-role="header">
  12.   <h1>Header</h1>
  13. </div>
  14. <div data-role="content">
  15.   <p>Content goes here</p>
  16. </div>
  17. <div data-role="footer">
  18.   <h4>Footer</h4>
  19. </div>
  20. </div>
  21. </body>
  22. </html>
复制代码


 


2. 在什么地方添加 jQuery 的方法调用?
  1. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
  2. <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
  3. <script>
  4. $(document).ready(function() {
  5.   // 在这里添加 jQuery 代码
  6. });
  7. </script>
  8. <script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
复制代码


 


3. 一次性禁用所有链接的 Ajax 导航
  1. <script>
  2. $(document).ready(function() {
  3.   // disable ajax nav
  4.   $.mobile.ajaxLinksEnabled = false;
  5. });
  6. </script>
复制代码




4. 防止某些关键条目被截断

某些比较长的条目会被自动截断并使用 ... 替换显示,该方法可避免出现这种情况

列表项:

 

  1. body .ui-li .ui-li-desc {
  2. white-space: normal;
  3. }
复制代码

 

For footer content:

 

  1. body .ui-footer .ui-title {
  2. white-space: normal;
  3. }
复制代码

 

5. Use media queries to target devices

One of the first questions I had with this library was how to target devices in the CSS (based on screen size). For example, I wanted a two-column layout for the iPad and a single column for smartphones. The absolute best way to accomplish this is with media queries.

With some simple media queries in place, you can quickly make the CSS target screen sizes. And with this type of targeting, we can quickly set up different layouts based on the available screen space by relying on conventional CSS techniques.

Two fantastic resources for this are:


6. 使用 jQuery 判断目标平台
  1. var deviceAgent = navigator.userAgent.toLowerCase();
  2. var agentID = deviceAgent.match(/(iphone|ipod|ipad|android)/);
  3. if(agentID.indexOf("iphone")>=0){
  4.   alert("iphone");
  5. }
  6. if(agentID.indexOf("ipod")>=0){
  7.   alert("ipod");
  8. }
  9. if(agentID.indexOf("ipad")>=0){
  10.   alert("ipad");
  11. }
  12. if(agentID.indexOf("android")>=0){
  13.   alert("android");
  14. }
复制代码



7. 使用完整路径来处理表单 action

For example, I’ve found that this form tag never finds its target:

 

  1. <form action=" form-handler.php " method="get" >
复制代码

 

Whereas a full path like this works as expected:

 

  1. <form action="/current-directory/form-handler.php" method="get" >
复制代码

 

Also, be sure that the results from the form handler produce a full, valid jQuery mobile page, as shown in tip #1.


8. 创建弹出对话框
  1. <a href="#pop.html" data-rel="dialog">Pop up!</a>
复制代码


 


9. “取消” + “保存” 的组合按钮
  1. <fieldset>
  2. <div><button type="submit" data-theme="c">Cancel</button></div>
  3. <div><button type="submit" data-theme="b">Submit</button></div>
  4. </fieldset>
复制代码


 


10. Create a column structure on your own

In my quest to optimally structure a single page for multiple devices, I found myself combining the media query tricks above with the “columns in any order” technique.

Fortunately, web developers figured out long ago how to move columns around. By combining this technique with media queries, we can very easily set up various structures depending on the screen size we’re working with.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值