0
点赞
收藏
分享

微信扫一扫

小程序的一些函数调用方法

直接调取当前js中的其他方法,
调取参数that.bindViewTap();

跳转页面




function


'../page4/page4'



},





全局变量使用方法


a.js




var



Page({




data: {




hex1: [],





//设置全局变量


if (hex1 !=
null) {




app.globalData.hex1 = hex1;




}








b.js




接收全局变量



var


Page({ data:{ hex1:[] },

onLoad:function(options){ this.setData({ hex1:getApp().globalData.hex1 }); },
})









获取事件的方法:

function


console.log('事件event',e)


}







监听input方法




a.wxml页面



<
input
type=
"number"
maxlength=
"2"
placeholder=
"小于100分钟"
placeholder-class=
"psection"
bindinput=
"listenerTimeInput"
/
>




a.js页面




//监听input框输入


function


this.data.time = e.detail.value;



'哒哒this.data.time',
this.data.time)




},








获取当前时间戳


var timestamp = Date.parse(
new


1000;



"当前时间戳为:"






时间转换为秒


var stime =
'';



var format =
'';



60;



'秒', stime);







转换为时间


function


var


"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


this.getFullYear() +
'').substr(
4



}



for (
var k
in


if (
new RegExp(
"(" + k +
")").test(format)) {



1


"00" + date[k]).substr((
""



}




}



return



}



var oktime =
'';



'yyyy-MM-dd h:m:s');







//获取当前时间


var date =
new


var seperator1 =
"-";



var seperator2 =
":";



var month = date.getMonth() +
1;



'大大', month);



var


if (month >=
1 && month <=
9) {



"0"



}



'大大', month);



if (strDate >=
0 && strDate <=
9) {



"0"



}



var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
" "


'当前时间', currentdate);



'年', date.getFullYear());



'月', month);



'日', date.getDate());



'时', date.getHours())



'分', date.getMinutes())









转为串



oktime = oktime.toString();







提取数值


var oktime = oktime.replace(/[^0-9]/ig,
"");



'oktime', oktime);







获取年


var year1 =
'';
var month1 =
'';
var date1 =
'';
var hours1 =
'';
var min1 =
'';



2,
4);



'year1', year1);



4,
6);



'month1', month1);



6,
8);



'date1', date1);



8,
10);



'hours1', hours1);



10,
12);



'min1', min1);




转换为16进制



var zhen4000 = parseInt(zhen400);



console.log('飞zhen4000', zhen4000)



zhen4000 = zhen4000.toString(16);



console.log('@@@@@zhen4000', zhen4000);








将值由16进制转10进制


16);







// 进行异或运算


//注:我使用过16进制的异或运算,没成功,最后使用了比较复杂的方法,由十六进制转化为十进制异或运算,将得到的值在转为十六进制



zhen9 = zhen1 ^ zhen2




点击事件url传值



wx.redirectTo({



'../page1/page1?deviceId='+title+
'&name='+name,



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



<
navigator

bindtap
=
"bindViewTap1"

id
=
'time1'

url
=
"../page5/page5"

hover-class
=
"navigator-hover"

>




.js




function


//hex1


var


'坎坎坷坷扩id',id);





设置跳出循环




//跳出循环,只运行一次


在data()里面添加

'',



var flag =
true;



if
(flag) {



that.bindViewTap3();




that.bindViewTap2();



false;




}










函数间传值




//设置全局data




data{rtime:''}




btn1: function(e){
this.setData({
rtime : time
})
}
btn2:funciton(e){
console.log('###@@@@@#',this.data.rtime)
}

举报

相关推荐

0 条评论