PhoneGap-----Contacts

Everything in the code!!!

 

<!DOCTYPE html>

<html>

  <head>

    <title>Contact Example</title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

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

      <script type="text/javascript" charset="uft-8">

	    document.addEventListener("deviceready",onDeviceReady,false);

		

		function onDeviceReady(){			

			 var options = new ContactFindOptions();

             options.filter="js";

             filter = ["displayName","phoneNumbers"];

             navigator.contacts.find(filter, onSuccess, onError, options);

		}

		

		function onSuccess(contacts){

			var myresults = document.getElementById("results");

			var string = "";

			for (var i = 0; i < contacts.length; i++) {

            // display phone numbers

                for (var j = 0; j < contacts[i].phoneNumbers.length; j++) {

                   string += "Name: " + contacts[i].displayName + "<br/>" +

				      "Type: "      + contacts[i].phoneNumbers[j].type  + "\n" +

                      "Value: "     + contacts[i].phoneNumbers[j].value + "\n" +

                      "Preferred: " + contacts[i].phoneNumbers[j].pref;

                }

            }

			myresults.innerHTML = string;

		}

		

		function onError(contactError){

			alert('Ooops!');

		}

		

      </script>

  </head>

  <body>

    <h1>Contacts</h1>

    <div id="results"></div>

  </body>

</html>


 

 

你可能感兴趣的:(PhoneGap)