微信小程序登錄時(shí)如何獲取input框中的內(nèi)容
這篇文章主要介紹了微信小程序登錄時(shí)如何獲取input框中的內(nèi)容,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
最近寫小程序項(xiàng)目遇到一些問題,今天整理下這些問題的解決方法,希望對(duì)用戶有幫助。下面是登錄頁,點(diǎn)擊登錄時(shí)獲取input框中的值,
效果如下:
wxml布局如下:
<view > <input type="text" placeholder-style="color:#fff;" bindinput="userNameInp" placeholder="請(qǐng)輸入賬號(hào)" /> </view> <view > <input password placeholder-style="color:#fff;" bindinput="usePasswordInp" placeholder="請(qǐng)輸入密碼"/> </view> <button class="loginBtn" bindtap='loginFn'>登錄</button>
js代碼如下:
const app = getApp();
Page({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
userName: "",
passWord: "",
},
//監(jiān)聽輸入的賬號(hào)
userNameInp: function (e) {
this.data.userName = e.detail.value;
},
//監(jiān)聽輸入的密碼
usePasswordInp: function (e) {
this.data.passWord = e.detail.value;
},
//登錄
loginFn: function () {
var that = this;
if (that.data.userName.length == 0 || that.data.passWord.length == 0) {
wx.showToast({
title: '賬號(hào)或密碼為空',
icon: 'loading',
duration: 2000
})
} else {
wx.showLoading({
title: '登錄中...',
})
wx.request({
url: 'https://localhost:8180/exam/login',
data: {
username: that.data.userName,
password: that.data.passWord
},
header: {
'content-type': 'application/x-www-form-urlencoded' // 默認(rèn)值
},
method: 'post',
success: function (res) {
wx.hideLoading();
wx.removeStorageSync('sessionid');
// console.log('登錄成功', res.data.data);
if (res.data.code == "0000") {
wx.showToast({
title: '登錄成功',
icon: 'success',
duration: 1000
})
wx.setStorageSync('sessionid', res.header['Set-Cookie']); //保存Cookie到Storage
wx.setStorage({
key: 'myData',
data: res.data.data
})
wx.redirectTo({
url: '/pages/index/index',
})
} else {
wx.showToast({
title: '登錄失敗',
icon: 'none',
duration: 2000
})
}
},
fail: function (e) {
wx.showToast({
title: '服務(wù)器出現(xiàn)錯(cuò)誤',
icon: 'none',
duration: 2000
})
}
})
}
},
//跳轉(zhuǎn)到忘記密碼頁面
onTapDayWeather() {
wx.navigateTo({
url: '/pages/updatepwd/updatepwd',
})
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad: function (options) {
},
})
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript接口的實(shí)現(xiàn)三種方式(推薦)
這篇文章主要介紹了JavaScript接口的實(shí)現(xiàn)三種方式,有注釋法,檢查屬性法和鴨式辨行法,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧2016-06-06
JavaScript保留兩位小數(shù)的2個(gè)自定義函數(shù)
這篇文章主要介紹了JavaScript保留兩位小數(shù)的2個(gè)自定義函數(shù),需要的朋友可以參考下2014-05-05
微信小程序canvas.drawImage完全顯示圖片問題的解決
這篇文章主要介紹了微信小程序canvas.drawImage完全顯示圖片問題的解決,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-11-11
JavaScript+Canvas實(shí)現(xiàn)文字粒子流特效
看到大師級(jí)的canvas文字粒子動(dòng)畫,要10個(gè)jq幣才能下載啊,我內(nèi)心的小鹿蠢蠢欲動(dòng),我也要寫一個(gè)。所以本文就來用Canvas實(shí)現(xiàn)簡單的文字粒子流特效,希望對(duì)大家有所幫助2023-01-01
bootstrap側(cè)邊欄圓點(diǎn)導(dǎo)航
這篇文章主要為大家詳細(xì)介紹了bootstrap側(cè)邊欄圓點(diǎn)導(dǎo)航效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01
underscore之Collections_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
underscore為集合類對(duì)象提供了一致的接口。集合類是指Array和Object,暫不支持Map和Set。下面通過本文給大家分享underscore之Collections的相關(guān)知識(shí),需要的的朋友參考下吧2017-07-07
微信小程序?qū)W習(xí)筆記之登錄API與獲取用戶信息操作圖文詳解
這篇文章主要介紹了微信小程序?qū)W習(xí)筆記之登錄API與獲取用戶信息操作,結(jié)合實(shí)例形式分析了微信小程序登陸請(qǐng)求及后臺(tái)交互相關(guān)操作技巧,并結(jié)合圖文形式進(jìn)行說明,需要的朋友可以參考下2019-03-03
詳解JavaScript數(shù)組和字符串中去除重復(fù)值的方法
這篇文章主要介紹了詳解JavaScript數(shù)組和字符串中去除重復(fù)值的方法,及利用各種限制條件對(duì)數(shù)組和字符串進(jìn)行過濾,需要的朋友可以參考下2016-03-03

