无语
无语
  • 发布:2015-07-02 13:16
  • 更新:2018-10-02 19:57
  • 阅读:6910

何如获取本机手机号码。

分类:HTML5+
2015-07-02 13:16 负责人:无 分享
已邀请:
李晓龙

李晓龙

我给你 我写的代码 上面 可以获取 和搜索 但是我利用了 一个模版插件我会把插件贴出来 你看看

这个是源码

<!DOCTYPE html>
<html>

<head>  
    <meta charset="utf-8">  
    <title>Hello MUI</title>  
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">  
    <meta name="apple-mobile-web-app-capable" content="yes">  
    <meta name="apple-mobile-web-app-status-bar-style" content="black">  

    <!--标准mui.css-->  
    <link rel="stylesheet" href="../css/mui.min.css">  
    <!--App自定义的css-->  
    <link rel="stylesheet" type="text/css" href="../css/app.css" />  
    <style>  
        .mui-btn {  
            display: block;  
            width: 120px;  
            margin: 10px auto;  
        }  
        #info {  
            padding: 20px 10px;  
        }  
    </style>  

</head>  
<script src="../js/laytpl.js" type="text/javascript" charset="utf-8"></script>  

<body>  
    <header class="mui-bar mui-bar-nav">  
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>  
        <h1 class="mui-title">电话本</h1>  

    </header>  
    <div class="mui-content">  
    <div class="mui-input-row mui-search">  
                <input id="search" type="search" class="mui-input-speech" placeholder="请说姓名">  

            </div>  
        <div id="view">  

        </div>  
    </div>  
    <script id="demo" type="text/html">  

        <ul>  
            {{# for(var i = 0, len = d.length; i  
            < len; i++){ var tel="" }} {{# if(typeof(d[i].phoneNumbers[0])!="undefined" ) { tel=d[i].phoneNumbers[0].value; } }} <p>{{d[i].displayName}}:<a href="tel:{{tel}}">{{tel}}</a>  
                </p>  
                {{# } }}  
        </ul>  
    </script>  

    <script src="../js/mui.min.js"></script>  
    <script type="text/javascript" charset="utf-8">  
     //语音识别完成事件  
     var name="**";  
        document.getElementById("search").addEventListener('recognized', function(e) {  
        //  name = "*"+e.detail.value+"*";  
        //  getPhone();  
        });  
        document.getElementById("search").addEventListener('change', function(e) {  

            name = "*"+this.value+"*";  
            getPhone();  
        });  

         //mui初始化  
        mui.init({  
            swipeBack: true //启用右滑关闭功能  
        });  

        document.addEventListener("plusready", getPhone, false);  
        function getPhone(){  
            plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, function(addressbook) {  
                addressbook.find(["displayName", "phoneNumbers"], function(contacts) {  
                    var gettpl = document.getElementById('demo').innerHTML;  
                    laytpl(gettpl).render(contacts, function(html) {  
                        document.getElementById('view').innerHTML = html;  
                    });  
                }, function() {  
                    alert("error");  
                }, {  
                    filter:[{logic:"or",field:"displayName",value:name},{logic:"or",field:"nickname",value:name}],  
                    multiple: true  
                });  
            }, function(e) {  
                alert("Get address book failed: " + e.message);  
            });  
        }  
    </script>  
</body>  

</html>

下面是插件JS

;!function(){"use strict";var f,b={open:"{{",close:"}}"},c={exp:function(a){return new RegExp(a,"g")},query:function(a,c,e){var f=["#([\s\S])+?","([^{#}])*?"][a||0];return d((c||"")+b.open+f+b.close+(e||""))},escape:function(a){return String(a||"").replace(/&(?!#?[a-zA-Z0-9]+;)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&#39;").replace(/"/g,"&quot;")},error:function(a,b){var c="Laytpl Error:";return"object"==typeof console&&console.error(c+a+"\n"+(b||"")),c+a}},d=c.exp,e=function(a){this.tpl=a};e.pt=e.prototype,e.pt.parse=function(a,e){var f=this,g=a,h=d("^"+b.open+"#",""),i=d(b.close+"$","");a=a.replace(/[\r\t\n]/g," ").replace(d(b.open+"#"),b.open+"# ").replace(d(b.close+"}"),"} "+b.close).replace(/\/g,"\\").replace(/(?="|')/g,"\").replace(c.query(),function(a){return a=a.replace(h,"").replace(i,""),'";'+a.replace(/\/g,"")+'; view+="'}).replace(c.query(1),function(a){var c='"+(';return a.replace(/\s/g,"")===b.open+b.close?"":(a=a.replace(d(b.open+"|"+b.close),""),/^=/.test(a)&&(a=a.replace(/^=/,""),c='"+escape('),c+a.replace(/\/g,"")+')+"')}),a='"use strict";var view = "'+a+'";return view;';try{return f.cache=a=new Function("d, escape",a),a(e,c.escape)}catch(j){return delete f.cache,c.error(j,g)}},e.pt.render=function(a,b){var e,d=this;return a?(e=d.cache?d.cache(a,c.escape):d.parse(d.tpl,a),b?(b(e),void 0):e):c.error("no data")},f=function(a){return"string"!=typeof a?c.error("Template not found"):new e(a)},f.config=function(a){a=a||{};for(var c in a)b[c]=a[c]},f.v="1.1","function"==typeof define?define(function(){return f}):"undefined"!=typeof exports?module.exports=f:window.laytpl=f}();

  • 无语 (作者)

    你这是获取本机的手机号码,我看怎么想获取通讯录呢

    2015-07-02 13:42

潇洒哥gg

潇洒哥gg

只有你自己才能看清楚写的什么鬼

该问题目前已经被锁定, 无法添加新回复