* 代码中的服务器地址和参数要替换成你自己的。
* 代码中的判断不够完善请自行修改。
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title></title> <script type="text/javascript" src="js/jquery-1.8.2.min.js"></script> <script type="text/javascript" src="js/cordova-2.2.0.js"></script> <script type="text/javascript"> $(document).bind('deviceready',function(){ // 检查设备的网络状况 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'; alert('Connection type: ' + states[networkState]); // 登录 $('#submit').bind('touchstart',function(){ var username=$.trim($('#uname').val()); var userpass=$.trim($('#upass').val()); if(username!=''&&userpass!='') { $.post('服务器地址',{参数},function(data){ var data = eval('('+data+')'); $('#mes').html(data.email); }); }else{ navigator.notification.alert('用户名或密码不能为空'); } }); }); </script> </head> <body> username: <input type="text" id="uname" /> <br /> userpass: <input type="password" id="upass" /> <br /> <input type="button" value="Login" id="submit" /> <br /> <span id="mes"></span> </body> </html>