首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

搭建基于 PhoneGap 框架的 Mobile 应用(4)

搭建基于 PhoneGap 框架的 Mobile 应用(4)

  • index.html 页面                         在 /assets/www 目录下创建一个新的 HTML 页面命名为 index.html,并拷贝清单 3 的内容到 index.html 文件。
    清单 3: Index.html
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    <!DOCTYPE HTML>
    <html>
    <head>
       <meta name="viewport" content="width=320; user-scalable=no" />
       <meta http-equiv="Content-type" content="text/html; charset=utf-8" >
       <title>PhoneGap</title>
    <link rel="stylesheet" href="master.css" type="text/css" media="screen"
    title="no title" charset="utf-8" >
    <script type="text/javascript" charset="utf-8" src="phonegap.0.9.4.js"
    ></script>
    <script type="text/javascript" charset="utf-8" >
        //show device information
    var deviceInfo = function (){      
         document.getElementById("platform").innerHTML = device.platform;
         document.getElementById("version").innerHTML = device.version;
         document.getElementById("uuid").innerHTML = device.uuid;
         document.getElementById("name").innerHTML = device.name;
         document.getElementById("width").innerHTML = screen.width;
         document.getElementById("height").innerHTML = screen.height;
         document.getElementById("colorDepth").innerHTML = screen.colorDepth;
           };
          //listen the device ready event and get the device information.
    function init(){
    document.addEventListener("deviceready", deviceInfo, true );
            }

    // get device contacts list by the contacts API.
    function get_contacts()
            {
    var obj = new ContactFindOptions();
    obj.filter="";
    obj.multiple=true ;
    obj.limit=5;
    navigator.service.contacts.find(["name","displayName", "phoneNumbers",
    "emails"],contacts_success, fail, obj);
            }

    function fail(fail)
           {
             alert(fail);
           }
    function contacts_success(contacts)
    {
    var result = "";
    for (var i=0;i<contacts.length;i++)
                {
    result += "Name: " + contacts.name.givenName + ", displayName: "+
    contacts.displayName + ",Email:" + contacts.emails[0].value;
    result += "<br>";
                }
    document.getElementById("conlist").innerHTML = result;
    alert(contacts.length + ' contacts returned.' );
            }
    </script>

    </head>
    <body onload="init();" id="stage" class="theme" >
       <h1>Welcome to PhoneGap!</h1>
       <h2>this file is located at assets/index.html</h2>
       <div id="info" >
           <h4>Platform: <span id="platform" > &nbsp;</span>,
           Version: <span id="version" >&nbsp;</span></h4>
           <h4>UUID: <span id="uuid" > &nbsp;</span>,
           Name: <span id="name" >&nbsp;</span></h4>
           <h4>Width: <span id="width" > &nbsp;</span>,
           Height: <span id="height" >&nbsp;
           </span>, Color Depth: <span id="colorDepth" ></span></h4>
        </div>   
       <a href="#" class="btn large" onclick="get_contacts();">
       Get phone's contacts</a>
        <a href="http://w3.ibm.com/w3odw/spg/index_default.html" class="btn large"
          >Access IBM Home Page</a>
       <form action="http://x.x.x.x:8080/WebTest/index.jsp" method="get" >
    Username: <input type="text" name="name" />
    <input type="submit" />
    </form>
       <div id="conlist" >
       </div>     
    </body>
    </html>




注意:<formaction="http://x.x.x.x:8080/WebTest/index.jsp"method="get">中的“x.x.x.x”应为运行着一个 context root 为 WebTest 的 Web 应用的主机地址(IP 或者 HostName),WebTest 项目可从本文档提供的链接中下载。
返回列表