http://www.aliued.cn/2012/04/11/%E5%88%9D%E8%AF%86phonegap.html
使用phonegap让前端开发人员也能构建自己绚丽的手机应用程序
phonegap框架是一个开源框架
封装了各种手机系统的常用功能,供javascript使用,
对html5支持较好(css,html5标签,javascript),
配置好相关的属性,就可以完全像开发web一样开发自己的手机程序。
http://banxi1988.iteye.com/blog/1292494
注意引入顺序
<link rel="stylesheet" type="text/css" href="css/themes/default/jquery.mobile-1.1.0.min.css" /> <script type="text/javascript" charset="utf-8" src="js/cordova-2.0.0.js"></script> <script type="text/javascript" charset="utf-8" src="js/jquery-1.7.1.min.js"></script> <script type="text/javascript" charset="utf-8" src="js/jquery.mobile-1.1.0.min.js"></script>
phonegap文档自带的
phonegap-phonegap-2dbbdab\lib\android\example\assets\www\main.js
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; }; var getLocation = function() { var suc = function(p) { alert(p.coords.latitude + " " + p.coords.longitude); }; var locFail = function() { }; navigator.geolocation.getCurrentPosition(suc, locFail,{enableHighAccuracy:true}); }; var beep = function() { navigator.notification.beep(2); }; var vibrate = function() { navigator.notification.vibrate(0); }; function roundNumber(num) { var dec = 3; var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec); return result; } var accelerationWatch = null; function updateAcceleration(a) { document.getElementById('x').innerHTML = roundNumber(a.x); document.getElementById('y').innerHTML = roundNumber(a.y); document.getElementById('z').innerHTML = roundNumber(a.z); } var toggleAccel = function() { if (accelerationWatch !== null) { navigator.accelerometer.clearWatch(accelerationWatch); updateAcceleration({ x : "", y : "", z : "" }); accelerationWatch = null; } else { var options = {}; options.frequency = 1000; accelerationWatch = navigator.accelerometer.watchAcceleration( updateAcceleration, function(ex) { alert("accel fail (" + ex.name + ": " + ex.message + ")"); }, options); } }; var preventBehavior = function(e) { e.preventDefault(); }; function dump_pic(data) { var viewport = document.getElementById('viewport'); console.log(data); viewport.style.display = ""; viewport.style.position = "absolute"; viewport.style.top = "10px"; viewport.style.left = "10px"; document.getElementById("test_img").src = data; } function fail(msg) { alert(msg); } function show_pic() { navigator.camera.getPicture(dump_pic, fail, { quality : 50 }); } function close() { var viewport = document.getElementById('viewport'); viewport.style.position = "relative"; viewport.style.display = "none"; } function contacts_success(contacts) { alert(contacts.length + ' contacts returned.' + (contacts[2] && contacts[2].name ? (' Third contact is ' + contacts[2].name.formatted) : '')); } function get_contacts() { var obj = new ContactFindOptions(); obj.filter = ""; obj.multiple = true; navigator.contacts.find( [ "displayName", "name" ], contacts_success, fail, obj); } function check_network() { var networkState = navigator.network.connection.type; var states = {}; states[Connection.UNKNOWN] = 'Unknown connection'; states[Connection.ETHERNET] = 'Ethernet connection'; states[Connection.WIFI] = 'WiFi connection'; states[Connection.CELL_2G] = 'Cell 2G connection'; states[Connection.CELL_3G] = 'Cell 3G connection'; states[Connection.CELL_4G] = 'Cell 4G connection'; states[Connection.NONE] = 'No network connection'; confirm('Connection type:\n ' + states[networkState]); } var watchID = null; function updateHeading(h) { document.getElementById('h').innerHTML = h.magneticHeading; } function toggleCompass() { if (watchID !== null) { navigator.compass.clearWatch(watchID); watchID = null; updateHeading({ magneticHeading : "Off"}); } else { var options = { frequency: 1000 }; watchID = navigator.compass.watchHeading(updateHeading, function(e) { alert('Compass Error: ' + e.code); }, options); } } function init() { // the next line makes it impossible to see Contacts on the HTC Evo since it // doesn't have a scroll button // document.addEventListener("touchmove", preventBehavior, false); document.addEventListener("deviceready", deviceInfo, true); }