效果圖
wxml
view bindtap="getCode">{{ code }}view>
js
Page({
data: {code: ''
},
onLoad() {//進入頁面就調用方法 創建一個隨機驗證碼this.createCode()
},getCode() {//點擊調用創建驗證碼方法this.createCode()
},//創建隨機驗證碼方法
createCode() {let code = ''; //初始化驗證碼let codeLength = 6; //設置驗證碼長度//設置隨機字符let txt = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');//循環for(let i = 0; i codeLength; i++) {//設置隨機數范圍let index = Math.floor(Math.random() * 36);code += txt[index];}//動態設置數據this.setDate({code})
}
})
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。