现在的位置: 首页 > 综合 > 正文

jqMobi插件(1)–HTML格式的ActionSheet

2018年05月20日 ⁄ 综合 ⁄ 共 2159字 ⁄ 字号 评论关闭

现在在手机客户端上Action Sheet非常常见,比如微信中的分享按钮菜单,下面我们使用jqMobi实现一个Action Sheet,如下:

首先右击上面的按钮选择审查元素(我用的是Chrome浏览器,先按F12)

  1. <a class="button" onclick="showCustomHtmlSheet()">Show Custom Html Sheet</a>  

然后Ctrl + F查找 showCustomHtmlSheet()方法

代码贴出如下:

  1. function showCustomHtmlSheet() {  
  2.         $("#afui").actionsheet('<a  >Back</a><a  onclick="alert(\'hi\');" >Show Alert 3</a><a  onclick="alert(\'goodbye\');">Show Alert 4</a>');  
  3. }  

我们可以看到上面的函数中有三个按钮链接,上图中最后一个Cancel是系统默认的取消按钮。

再Ctrl + F查找一个 plugins,可以看到如下一行

  1. <link rel="stylesheet" type="text/css" href="plugins/css/af.actionsheet.css">  

好吧我们下面开始在我们的工程中实现如上效果:

首先引入af.actionsheet.css文件

将上面的代码放入content中

  1. <!DOCTYPE html>   
  2. <html>  
  3. <head>  
  4. <meta charset="utf-8">  
  5. <title>jqMobi</title>  
  6. <link href="css/af.ui.css" rel="stylesheet" type="text/css"/>  
  7. <link href="css/icons.css" rel="stylesheet" type="text/css"/>  
  8. <link rel="stylesheet" type="text/css" href="plugins/css/af.actionsheet.css">  
  9. <script src="appframework.js" type="text/javascript"></script>  
  10. <script src="ui/appframework.ui.js" type="text/javascript"></script>  
  11. </head>   
  12. <body>   
  13.     <div id="afui">  
  14.         <div id="header">  
  15.             <!-- any additional HTML you want can go here -->  
  16.             <a onclick="$.ui.toggleSideMenu();" class="button">Toggle Side Menu</a>  
  17.         </div>  
  18.         <div id="content">  
  19.             <!-- this is where your panels will go -->  
  20.             <div id="main" title="Welcome" class="panel" selected="true">  
  21.                <a class="button" onclick="showCustomHtmlSheet()">Show Custom Html Sheet</a>  
  22.             </div>  
  23.             <div id="about" title="About" class="panel" data-nav="second_nav">  
  24.             <!-- by setting data-nav the "second_nav" will be shown on this panel -->  
  25.             </div>  
  26.         </div>  
  27.         //底部  
  28.         <div id="navbar">  
  29.         <a target="#welcome" class="icon home">Home</a>  
  30.         </div>  
  31.     </div>  
  32.     <script>  
  33.           
  34.         function showCustomHtmlSheet() {  
  35.             $("#afui").actionsheet('<a  >Back</a><a  onclick="alert(\'hi\');" >Show Alert 3</a><a  onclick="alert(\'goodbye\');">Show Alert 4</a>');  
  36.         }  
  37.   
  38.                       
  39.     </script>  
  40. </body>  
  41. </html>  

运行结果:

抱歉!评论已关闭.