详解微信小程序的不同函数调用的几种方法


Posted in Javascript onMay 08, 2019

一、调取参数

直接调取当前js中的方法,

调取参数that.bindViewTap();

二、跳转页面

navigateTo: function () {
wx.navigateTo({ url: '../page4/page4' });
},
 
 
全局变量使用方法
a.js
var app = getApp()
Page({
data: {
hex1: [],
})}
//设置全局变量
if (hex1 != null) {
app.globalData.hex1 = hex1;
}
 
b.js
接收全局变量
var app = getApp()
Page({
 data:{
  hex1:[]
 },
 
onLoad:function(options){
   this.setData({
   hex1:getApp().globalData.hex1
  });
 },
 
})

三、获取事件的方法:

获取事件的方法:
bindViewTap1: function (e) {
console.log('事件event',e)
}
 
监听input方法
a.wxml页面
<input type="number" maxlength="2" placeholder="小于100分钟" placeholder-class="psection" bindinput="listenerTimeInput" />
 
a.js页面
//监听input框输入
listenerTimeInput: function (e) {
this.data.time = e.detail.value;
console.log('哒哒this.data.time', this.data.time)
},
 
获取当前时间戳
var timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
console.log("当前时间戳为:" + timestamp);
 
时间转换为秒
var stime = '';
var format = '';
stime = time * 60;
console.log('秒', stime);
 
转换为时间
Date.prototype.format = function (format) {
var date = {
"M+": this.getMonth() +1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() +3) /3),
"S+": this.getMilliseconds()
};
if (/(y+)/i.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() +'').substr(4 - RegExp.$1.length));
}
for (var kin date) {
if (new RegExp("(" + k +")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1
? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
}
}
return format;
}
var oktime = '';
oktime = newDate.format('yyyy-MM-dd h:m:s');
 
//获取当前时间
var date = new Date();
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
console.log('大大', month);
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
console.log('大大', month);
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds();
console.log('当前时间', currentdate);
console.log('年', date.getFullYear());
console.log('月', month);
console.log('日', date.getDate());
console.log('时', date.getHours())
console.log('分', date.getMinutes())
 
 
转为串
oktime = oktime.toString();
 
提取数值
var oktime = oktime.replace(/[^0-9]/ig, "");
console.log('oktime', oktime);
 
获取年 月 日 时 分 秒
var year1 = '';var month1 ='';var date1 ='';var hours1 ='';var min1 ='';
year1 = oktime.substring(2, 4);
console.log('year1', year1);
month1 = oktime.substring(4, 6);
console.log('month1', month1);
date1 = oktime.substring(6, 8);
console.log('date1', date1);
hours1 = oktime.substring(8, 10);
console.log('hours1', hours1);
min1 = oktime.substring(10, 12);
console.log('min1', min1);
 
转换为16进制
  
var zhen4000 = parseInt(zhen400);
  
console.log('飞zhen4000', zhen4000)
    
zhen4000 = zhen4000.toString(16);
 
console.log('@@@@@zhen4000', zhen4000);
 
将值由16进制转10进制
zhen1 = parseInt(zhen001, 16);
 
// 进行异或运算
//注:我使用过16进制的异或运算,没成功,最后使用了比较复杂的方法,由十六进制转化为十进制异或运算,将得到的值在转为十六进制
zhen9 = zhen1 ^ zhen2

四、点击事件url传值

点击事件url传值
wx.redirectTo({
url: '../page1/page1?deviceId='+title+'&name='+name,
success: function(res){
// success
},
 
.js传值到.wxml页面
js页面
this.setData({
ntc: ntc,
result: ntc
})
wxml页面
<rich-text class='tep'>{{ntc}}℃</rich-text>
 
.wxml页面bindtap点击事件传值到.js 页面跳转 监听id传值
bindtap="bindViewTap1"值触发到到js里面的bindViewTap1:function方法
.wxml
<navigatorbindtap="bindViewTap1"id='time1'url="../page5/page5"hover-class="navigator-hover">
 
.js
bindViewTap1: function (e) {
//hex1
var id = e.currentTarget.id;
console.log('坎坎坷坷扩id',id);
}
 
设置跳出循环
//跳出循环,只运行一次
在data()里面添加
flag : '',
在你使用的方法里面加
var flag = true;
if (flag) {
that.bindViewTap3();
that.bindViewTap2();
flag = false;
}
 
 
函数间传值
//设置全局data
 data{rtime:''}
 
btn1: function(e){
 this.setData({
   rtime : time
  })
}
 
btn2:funciton(e){
 console.log('###@@@@@#',this.data.rtime)
}

以上所述是小编给大家介绍的微信小程序的不同函数调用的几种方法详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

Javascript 相关文章推荐
学习jquery必备 api中英文对照的chm手册 下载
May 03 Javascript
jQuery响应enter键的实现思路
Apr 18 Javascript
详解javascript中的事件处理
Nov 06 Javascript
JavaScript位置与大小(1)之正确理解和运用与尺寸大小相关的DOM属性
Dec 26 Javascript
javascript实现抽奖程序的简单实例
Jun 07 Javascript
jQuery查找和过滤_动力节点节点Java学院整理
Jul 04 jQuery
vue 添加vux的代码讲解
Nov 30 Javascript
ejsExcel模板在Vue.js项目中的实际运用
Jan 27 Javascript
js实现通过开始结束控制的计时器
Feb 25 Javascript
解决vue项目router切换太慢问题
Jul 19 Javascript
Openlayers显示地理位置坐标的方法
Sep 28 Javascript
微信小程序实现购物车小功能
Dec 30 Javascript
微信小程序Page中data数据操作和函数调用方法
May 08 #Javascript
vue中使用props传值的方法
May 08 #Javascript
vue权限问题的完美解决方案
May 08 #Javascript
基于vue-cli 路由 实现类似tab切换效果(vue 2.0)
May 08 #Javascript
微信小程序事件对象中e.target和e.currentTarget的区别详解
May 08 #Javascript
利用原生JavaScript实现造日历轮子实例代码
May 08 #Javascript
Vue2.0使用嵌套路由实现页面内容切换/公用一级菜单控制页面内容切换(推荐)
May 08 #Javascript
You might like
使用配置类定义Codeigniter全局变量
2014/06/12 PHP
php+xml实现在线英文词典查询的方法
2015/01/23 PHP
codeigniter中实现一次性加载多个view的方法
2015/03/20 PHP
PHP实现网站访问量计数器
2017/10/27 PHP
在Laravel 中实现是否关注的示例
2019/10/22 PHP
javascript框架设计之框架分类及主要功能
2015/06/23 Javascript
javascript处理a标签超链接默认事件的方法
2015/06/29 Javascript
javascript中setTimeout使用指南
2015/07/26 Javascript
深入nodejs中流(stream)的理解
2017/03/27 NodeJs
基于vue-resource jsonp跨域问题的解决方法
2018/02/03 Javascript
JS简易计算器实例讲解
2020/06/30 Javascript
微信小程序实现滚动Tab选项卡
2020/11/16 Javascript
[49:18]2018DOTA2亚洲邀请赛 3.31 小组赛 A组 OG vs TNC
2018/04/01 DOTA
python实现在pickling的时候压缩的方法
2014/09/25 Python
浅析Python中的join()方法的使用
2015/05/19 Python
基于python代码实现简易滤除数字的方法
2018/07/17 Python
python写日志文件操作类与应用示例
2019/07/01 Python
Pandas中DataFrame的分组/分割/合并的实现
2019/07/16 Python
python实现PID算法及测试的例子
2019/08/08 Python
PYcharm 激活方法(推荐)
2020/03/23 Python
python如何将图片转换素描画
2020/09/08 Python
浅析Python 字符编码与文件处理
2020/09/24 Python
python 读取串口数据的示例
2020/11/09 Python
Python识别处理照片中的条形码
2020/11/16 Python
Python实现中英文全文搜索的示例
2020/12/04 Python
html5+css如何实现中间大两头小的轮播效果
2018/12/06 HTML / CSS
Sofft鞋官网:世界知名鞋类品牌
2017/03/28 全球购物
Crabtree & Evelyn欧盟:豪华洗浴、身体和护发
2021/03/09 全球购物
英国运动风奢侈品购物网站:Maison De Fashion
2020/08/28 全球购物
Ibatis如何调用存储过程
2015/05/15 面试题
什么是.net的Remoting技术
2016/07/08 面试题
员工自我鉴定
2013/10/09 职场文书
2014年社区教育工作总结
2014/12/02 职场文书
2016年春节慰问信息
2015/03/25 职场文书
幼儿园元旦主持词
2015/07/06 职场文书
Python数据处理的三个实用技巧分享
2022/04/01 Python