mui关于页面间传值的方法
2016/3/25 方法0:fire传值 mui.openWindow({ url:"road_lineWindCar.html", id:"road_lineWindCar.html", waiting:{ autoShow:false }, extras:{ car:this.getAttribute("car"), //这里的值可以是你在函数体里的具体的值,我这里是把这些值写在(li)标签里的属性 hcCityName:this.getAttribute("hcCityName"), qcStoreName:this.getAttribute("qcStoreName") } }) 在预加载里写 mui.plusReady(function(){ var car = plus.webview.currentWebview().car; var hcCityName = plus.webview.currentWebview().hcCityName; var qcStoreName = plus.webview.currentWebview().qcStoreName; }) 方法1:mui实现页面间传值:fire传值 这种方法传值,有可能传不过去 第一步:要有目标页面 var roadLinePage = plus.webview.getWebviewById("choose_car.html"); 第二步:要有自定义事件 其中getQcCity就是事件 mui.fire(roadLinePage,"getQcCity",{ qcCityName:cityName, qcCityId:cityId }); 第三部:要在目标页面监听事件getQcCity window.addEventListener("getQcCity",function(event){ //获得事件参数 var id = event.detail.qcCityId;//获取传过来的值 document.getElementById("qcCity_").value=id; console.log("取车城市"+id); freshCarTable();//要执行的函数 }); 方法2: 本地存储--存储json格式的数据 localStorage.setItem(name, JSON.stringify(value)); var obj = localStorage.getItem(name); return mui.parseJSON(obj); /** * 本地存储Utils */ var localStorageUtils = { setParam: function (name, value) { if (value) { localStorage.setItem(name, JSON.stringify(value)); } }, getParam: function (name) { var obj = localStorage.getItem(name); return mui.parseJSON(obj); }, removeParam: function (key) { return localStorage.removeItem(key); } } H5+中本地存储使用-- 方法:3: 获取应用存储区中保存的键值对的个数 var foo = plus.storage.getLength(); 修改或添加键值(key-value)对数据到应用数据存储中 void plus.storage.setItem(key, value); 通过键(key)检索获取应用存储的值 var foo = plus.storage.getItem(key); 通过key值删除键值对存储的数据 void plus.storage.removeItem(key); 清除应用所有的键值对存储数据 void plus.storage.clear(); 获取键值对中指定索引值的key值 var foo = plus.storage.key(index); var keyNames=[]; var values=[]; var numKeys=plus.storage.getLength(); for(var i=0; i<numKeys; i++) { keyNames[i] = plus.storage.key(i); values[i] = plus.storage.getItem(keyNames[i]); }
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: HTML5+、mui开发移动app
- 下一篇: MUI移动端页面跳转