詳解微信小程序的不同函數(shù)調(diào)用的幾種方法
一、調(diào)取參數(shù)
直接調(diào)取當(dāng)前js中的方法,
調(diào)取參數(shù)that.bindViewTap();
二、跳轉(zhuǎn)頁(yè)面
navigateTo: function () {
wx.navigateTo({ url: '../page4/page4' });
},
全局變量使用方法
a.js
var app = getApp()
Page({
data: {
hex1: [],
})}
//設(shè)置全局變量
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)
}
監(jiān)聽input方法
a.wxml頁(yè)面
<input type="number" maxlength="2" placeholder="小于100分鐘" placeholder-class="psection" bindinput="listenerTimeInput" />
a.js頁(yè)面
//監(jiān)聽input框輸入
listenerTimeInput: function (e) {
this.data.time = e.detail.value;
console.log('噠噠this.data.time', this.data.time)
},
獲取當(dāng)前時(shí)間戳
var timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
console.log("當(dāng)前時(shí)間戳為:" + timestamp);
時(shí)間轉(zhuǎn)換為秒
var stime = '';
var format = '';
stime = time * 60;
console.log('秒', stime);
轉(zhuǎn)換為時(shí)間
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');
//獲取當(dāng)前時(shí)間
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('當(dāng)前時(shí)間', currentdate);
console.log('年', date.getFullYear());
console.log('月', month);
console.log('日', date.getDate());
console.log('時(shí)', date.getHours())
console.log('分', date.getMinutes())
轉(zhuǎn)為串
oktime = oktime.toString();
提取數(shù)值
var oktime = oktime.replace(/[^0-9]/ig, "");
console.log('oktime', oktime);
獲取年 月 日 時(shí) 分 秒
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);
轉(zhuǎn)換為16進(jìn)制
var zhen4000 = parseInt(zhen400);
console.log('飛zhen4000', zhen4000)
zhen4000 = zhen4000.toString(16);
console.log('@@@@@zhen4000', zhen4000);
將值由16進(jìn)制轉(zhuǎn)10進(jìn)制
zhen1 = parseInt(zhen001, 16);
// 進(jìn)行異或運(yùn)算
//注:我使用過(guò)16進(jìn)制的異或運(yùn)算,沒(méi)成功,最后使用了比較復(fù)雜的方法,由十六進(jìn)制轉(zhuǎn)化為十進(jìn)制異或運(yùn)算,將得到的值在轉(zhuǎn)為十六進(jìn)制
zhen9 = zhen1 ^ zhen2
四、點(diǎn)擊事件url傳值
點(diǎn)擊事件url傳值
wx.redirectTo({
url: '../page1/page1?deviceId='+title+'&name='+name,
success: function(res){
// success
},
.js傳值到.wxml頁(yè)面
js頁(yè)面
this.setData({
ntc: ntc,
result: ntc
})
wxml頁(yè)面
<rich-text class='tep'>{{ntc}}℃</rich-text>
.wxml頁(yè)面bindtap點(diǎn)擊事件傳值到.js 頁(yè)面跳轉(zhuǎn) 監(jiān)聽id傳值
bindtap="bindViewTap1"值觸發(fā)到到j(luò)s里面的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('坎坎坷坷擴(kuò)id',id);
}
設(shè)置跳出循環(huán)
//跳出循環(huán),只運(yùn)行一次
在data()里面添加
flag : '',
在你使用的方法里面加
var flag = true;
if (flag) {
that.bindViewTap3();
that.bindViewTap2();
flag = false;
}
函數(shù)間傳值
//設(shè)置全局data
data{rtime:''}
btn1: function(e){
this.setData({
rtime : time
})
}
btn2:funciton(e){
console.log('###@@@@@#',this.data.rtime)
}
以上所述是小編給大家介紹的微信小程序的不同函數(shù)調(diào)用的幾種方法詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- 微信小程序Page中data數(shù)據(jù)操作和函數(shù)調(diào)用方法
- 詳解微信小程序Page中data數(shù)據(jù)操作和函數(shù)調(diào)用
- 微信小程序 詳解Page中data數(shù)據(jù)操作和函數(shù)調(diào)用
- 詳解如何使用微信小程序云函數(shù)發(fā)送短信驗(yàn)證碼
- 詳解在微信小程序的JS腳本中使用Promise來(lái)優(yōu)化函數(shù)處理
- 微信小程序常用簡(jiǎn)易小函數(shù)總結(jié)
- 微信小程序提取公用函數(shù)到util.js及使用方法示例
- 解決mpvue + vuex 開發(fā)微信小程序vuex輔助函數(shù)mapState、mapGetters不可用問(wèn)題
- 微信小程序 功能函數(shù)小結(jié)(手機(jī)號(hào)驗(yàn)證*、密碼驗(yàn)證*、獲取驗(yàn)證碼*)
- 微信小程序 定義全局?jǐn)?shù)據(jù)、函數(shù)復(fù)用、模版等詳細(xì)介紹
相關(guān)文章
JavaScript中數(shù)組遍歷的7種方法小結(jié)
作為JavaScript開發(fā)人員,熟悉數(shù)組的遍歷和操作是非常重要的,數(shù)組遍歷是處理和操作數(shù)組元素的基本需求之一,本文將介紹JavaScript中的7種常見數(shù)組遍歷方法,幫助你成為數(shù)組操作的達(dá)人2023-11-11
BootStrap+Mybatis框架下實(shí)現(xiàn)表單提交數(shù)據(jù)重復(fù)驗(yàn)證
這篇文章主要介紹了BootStrap+Mybatis框架下實(shí)現(xiàn)表單提交數(shù)據(jù)重復(fù)驗(yàn)證功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03
原生javascript實(shí)現(xiàn)簡(jiǎn)單的datagrid數(shù)據(jù)表格
這篇文章主要介紹了原生javascript實(shí)現(xiàn)簡(jiǎn)單的datagrid數(shù)據(jù)表格的方法,效果十分棒,需要的朋友可以參考下2015-01-01
JavaScript如何實(shí)現(xiàn)防止重復(fù)的網(wǎng)絡(luò)請(qǐng)求的示例
這篇文章主要介紹了JavaScript如何實(shí)現(xiàn)防止重復(fù)的網(wǎng)絡(luò)請(qǐng)求的示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
【JS+CSS3】實(shí)現(xiàn)帶預(yù)覽圖幻燈片效果的示例代碼
下面小編就為大家?guī)?lái)一篇【JS+CSS3】實(shí)現(xiàn)帶預(yù)覽圖幻燈片效果的示例代碼。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家。給大家一個(gè)參考2016-03-03
基于JavaScript中標(biāo)識(shí)符的命名規(guī)則介紹
下面小編就為大家分享一篇基于JavaScript中標(biāo)識(shí)符的命名規(guī)則介紹,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01
JavaScript前端實(shí)現(xiàn)判斷登錄設(shè)備是移動(dòng)端還是PC
這篇文章主要為大家詳細(xì)介紹了JavaScript前端如何實(shí)現(xiàn)判斷登錄設(shè)備是移動(dòng)端還是PC,文中的示例代碼講解詳細(xì),有需要的小伙伴可以參考下2025-03-03

