Cordova学习——使用jquery框架+device设备插件完整过程
2016-01-25 23:45
591 查看
Cordova应用启动流程
一、命令行添加device设备信息插件
插件介绍地址:http://cordova.apache.org/docs/en/latest/cordova/plugins/pluginapis.html
在APP项目目录下:cordova plugin add cordova-plugin-device
二、加入jquery框架,方便开发
下载jquery.js放入AppName/assets/www/js目录下
三、修改项目代码
1、index.html中加入jquery框架代码
2、修改index.js
四、运行结果
一、命令行添加device设备信息插件
插件介绍地址:http://cordova.apache.org/docs/en/latest/cordova/plugins/pluginapis.html
在APP项目目录下:cordova plugin add cordova-plugin-device
二、加入jquery框架,方便开发
下载jquery.js放入AppName/assets/www/js目录下
三、修改项目代码
1、index.html中加入jquery框架代码
<head> …. <scripttype="text/javascript" src="js/jquery.min.js"></script> …. </head>
2、修改index.js
var app = { // Application Constructor initialize: function() { this.bindEvents(); }, // Bind Event Listeners // Bind any events that are required on startup. Common events are: // 'load', 'deviceready','offline', and 'online'. bindEvents: function() { document.addEventListener('deviceready',this.onDeviceReady, false); }, // deviceready Event Handler // The scope of 'this' is the event. In order to call the'receivedEvent' // function, we must explicitly call 'app.receivedEvent(...);' onDeviceReady: function() { app.receivedEvent('deviceready'); $(document).ready(function() { ready(); }); }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement =document.getElementById(id); var listeningElement =parentElement.querySelector('.listening'); var receivedElement =parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); console.log('Received Event: ' + id); } }; function ready() { $(".listening").hide(); $(".received").show(); $(".received").html("myphone is:"+device.model+";"+device.platform); } app.initialize();
四、运行结果
参考链接:http://www.jikexueyuan.com/course/799_4.html?ss=1
相关文章推荐
- jquery cookie操作方法
- jquery radio的取值 radio的选中 radio的重置
- jQuery 关于IE9上传文件无法进入后台问题的原因及解决办法
- 制作一个简洁的jquery插件
- DOM对象和JQuery对象的区别
- 通过jQuery的attr修改onclick
- jQuery中prop()、attr()的区别
- 基于jQuery下拉两级联动select
- JQUERY 判断选择器选择的对象 是否存在
- jquery:给正则表达式添加变量
- jQuery属性
- jquery toastmessage (Jquery类似安卓消息提示框)
- 利用jQuery封装插件的两种方式
- .map文件的作用以及在chorme下会报错找不到jquery-1.10.2.min.map文件,404 的原因
- jquery datatable隐藏字段获取
- jquery遍历时长度为空
- jquery 实现点击按钮后倒计时效果
- JQueryUI之Autocomplete
- Jquery中trigger和triggerHandler的区别
- Dojo与jQuery的比较