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

 

一、调取参数

直接调取当前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)
} 

 

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
微信小程序跨页面传多个ID可以通过多种方法实现。一种常用的方法是使用URL参数传递。在源页面中,可以通过wx.navigateTo或wx.redirectTo函数打开目标页面,并在URL中传递多个ID参数。例如,假设要传递id1和id2,可以使用如下代码: wx.navigateTo({ url: 'targetPage?id1=' + id1 + '&id2=' + id2 }) 在目标页面中,可以通过调用getCurrentPages()函数获取当前打开的页面栈,并通过options参数获取传递的ID参数。例如: const pages = getCurrentPages() const currentPage = pages[pages.length - 1] const options = currentPage.options const id1 = options.id1 const id2 = options.id2 除了URL参数传递,还可以使用全局变量或缓存存储来传递多个ID值。可以在源页面的全局变量中存储id1和id2的值,然后在目标页面中获取这些值即可。例如,在源页面中: getApp().globalData.id1 = id1 getApp().globalData.id2 = id2 wx.navigateTo({ url: 'targetPage' }) 在目标页面中,可以通过getApp().globalData.id1和getApp().globalData.id2来获取传递的ID值。 另一种方法是使用wx.setStorageSync函数将id1和id2存储到本地缓存中,在目标页面中使用wx.getStorageSync获取这些值。例如,在源页面中: wx.setStorageSync('id1', id1) wx.setStorageSync('id2', id2) wx.navigateTo({ url: 'targetPage' }) 在目标页面中,可以通过wx.getStorageSync('id1')和wx.getStorageSync('id2')来获取传递的ID值。 总之,微信小程序跨页面传递多个ID可以通过URL参数传递、全局变量或缓存存储来实现。开发者可以根据具体需求选择适合的方法

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值