微信開發微網站之jquery_mobile案例分析

高洛峰
發布: 2017-03-24 14:27:53
原創
1842 人瀏覽過

這堂課我們主要用到jquery_mobile來實現一個點電影播放網站

jquery_mobile(簡稱JQM)其實就是基於jquery開發出來的一套行動裝置框架,適應行動用戶端市場對瀏覽與體驗從而進一步的提升

jquery_mobile控制介紹

jquery_mobile的語法將各個控制項(widget)以data-role的形式定義好樣式,使用時直接引用,則可呼叫適合手機頁面顯示的樣式。

juqery_mobile的常用控制項如下所示:

微信開發微網站之jquery_mobile案例分析

#我們廢話不多說,開始寫第一個jquery_mobile的模版程序,改名為jqm1.html ,程式碼如下所示:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <!--宽高禁缩放 -->
        <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
        <!--类webapp--> 
        <meta name="apple-mobile-web-app-capable" content="yes">
        <!--状态条 --> 
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <!--电话号码不是链接 --> 
        <meta name="format-detection" content="telephone=no">
        <title>jQuery Mobile Web 应用程序</title>
        <link href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css"/>
        <script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script>
        <script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js" type="text/javascript"></script>
    </head>
    <body>
        <div data-role="page" id="page1">
            <div data-role="header">
                <h1>header</h1>
            </div>
            <div data-role="content">
                <ul data-role="listview">
                    <li><a href="#page1">第一页</a></li>
                    <li><a href="#page2">第二页</a></li>
                    <li><a href="#page3">第三页</a></li>
                    <li><a href="#page4">第四页</a></li>
                    <li><a href="#page5">第五页</a></li>
                </ul>
            </div>
            <div data-role="footer">
                <h1>页面脚注</h1>
            </div>
        </div>
        
        <div data-role="page" id="page2">
            <div data-role="header">
                <h1>header2</h1>
            </div>
            <div data-role="content">
                <img     style="max-width:90%" src="http://i.cnblogs.com/images/adminlogo.gif" / alt="微信開發微網站之jquery_mobile案例分析" >
            </div>
            <div data-role="footer">
                <h1>页面脚注</h1>
            </div>
        </div>
        
        <div data-role="page" id="page3">
            <div data-role="header">
                <h1>header3</h1>
            </div>
            <div data-role="content">
                内容3
            </div>
            <div data-role="footer">
                <h1>footer3</h1>
            </div>
        </div>
        
        <div data-role="page" id="page4">
            <div data-role="header">
                <h1>header4</h1>
            </div>
            <div data-role="content">
                <b>内容4</b>
            </div>
            <div data-role="footer">
                <h1>footer4    </h1>
            </div>
        </div>
        
        <div data-role="page" id="page5">
            <div data-role="header">
                <h1>header5</h1>
            </div>
            <div data-role="content">
                <h1>内容5</h1>
            </div>
            <div data-role="footer">
                <h1>footer5</h1>
            </div>
        </div>
    </body>
<html>
登入後複製
登入後複製
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <!--宽高禁缩放 -->
        <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
        <!--类webapp--> 
        <meta name="apple-mobile-web-app-capable" content="yes">
        <!--状态条 --> 
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <!--电话号码不是链接 --> 
        <meta name="format-detection" content="telephone=no">
        <title>jQuery Mobile Web 应用程序</title>
        <link href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css"/>
        <script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script>
        <script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js" type="text/javascript"></script>
    </head>
    <body>
        <div data-role="page" id="page1">
            <div data-role="header">
                <h1>header</h1>
            </div>
            <div data-role="content">
                <ul data-role="listview">
                    <li><a href="#page1">第一页</a></li>
                    <li><a href="#page2">第二页</a></li>
                    <li><a href="#page3">第三页</a></li>
                    <li><a href="#page4">第四页</a></li>
                    <li><a href="#page5">第五页</a></li>
                </ul>
            </div>
            <div data-role="footer">
                <h1>页面脚注</h1>
            </div>
        </div>
        
        <div data-role="page" id="page2">
            <div data-role="header">
                <h1>header2</h1>
            </div>
            <div data-role="content">
                <img     style="max-width:90%" src="http://i.cnblogs.com/images/adminlogo.gif" / alt="微信開發微網站之jquery_mobile案例分析" >
            </div>
            <div data-role="footer">
                <h1>页面脚注</h1>
            </div>
        </div>
        
        <div data-role="page" id="page3">
            <div data-role="header">
                <h1>header3</h1>
            </div>
            <div data-role="content">
                内容3
            </div>
            <div data-role="footer">
                <h1>footer3</h1>
            </div>
        </div>
        
        <div data-role="page" id="page4">
            <div data-role="header">
                <h1>header4</h1>
            </div>
            <div data-role="content">
                <b>内容4</b>
            </div>
            <div data-role="footer">
                <h1>footer4    </h1>
            </div>
        </div>
        
        <div data-role="page" id="page5">
            <div data-role="header">
                <h1>header5</h1>
            </div>
            <div data-role="content">
                <h1>内容5</h1>
            </div>
            <div data-role="footer">
                <h1>footer5</h1>
            </div>
        </div>
    </body>
<html>
登入後複製
登入後複製

由上面這段程式碼我們可以很清楚的了解到了我們的jquery_mobile是可以透過id來控制下面的清單的,有點像ecshop後台的添加商品那塊,

要注意的是紅色邊框裡面的程式碼,如下圖所示:

微信開發微網站之jquery_mobile案例分析

#然後再寫個fs.php的程序,主要讓他向指定使用者推送連結的,程式碼如下所示:

<?php
    header(&#39;content-type:text/html;charset=utf-8&#39;);
    require_once &#39;get_token.php&#39;;
    require_once &#39;common.php&#39;;
    //这时,也可以通过客户服务接口,把这个url地址发送给用户
    $contentStr = "体验一下jquery moible \n\n http://weixin.showtp.com/jqm1.html";
    $fromUsername = &#39;oB1_6tw1NBlGdqSsTCl5anZ7MEU4&#39;;
    //使用url编码
    $contentStr = urlencode($contentStr);
    $content_arr = array(&#39;content&#39; => "{$contentStr}");
    $reply_arr = array(&#39;touser&#39; => "{$fromUsername}", &#39;msgtype&#39; => &#39;text&#39;, &#39;text&#39; => $content_arr);
    //编码成json格式
    $post = json_encode($reply_arr);
    //url解码
    $post = urldecode($post);
    $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$access_token}";
    http_request($url, $post);
    echo &#39;发送成功!&#39;;
登入後複製

然後存取fs.php效果如下所示:

微信開發微網站之jquery_mobile案例分析

我們手機端將會接收到所推送的訊息了,我們點擊進去即可,我們也可以透過用瀏覽器縮小的形式就可以看到jquery_mobile成功縮放的效果,如下圖:

微信開發微網站之jquery_mobile案例分析

以上是微信開發微網站之jquery_mobile案例分析的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!