本文實例講述了微信小程序簡單實現form表單獲取輸入數據功能。分享給大家供大家參考,具體如下:
1、效果展示
2、關鍵代碼
index.wxml
<form bindsubmit="formBindsubmit" bindreset="formReset"> <view style="display:flex;"> <label>用戶名:</label> <input name="userName" placeholder="請輸入用戶名!" /> </view> <view style="display:flex;"> <label>密碼:</label> <input name="psw" placeholder="請輸入密碼!" password="true" /> </view> <view style="display:flex;margin-top:30px;"> <button style="width:30%;" formType="submit" >登錄</button> <button style="width:30%" formType="reset" >重置</button> </view> </form> <view>{{tip}}</view> <view>{{userName}}</view> <view>{{psw}}</view>
index.js
Page({ data:{ // text:"這是一個頁面" tip:'', userName:'', psw:'' }, formBindsubmit:function(e){ if(e.detail.value.userName.length==0||e.detail.value.psw.length==0){ this.setData({ tip:'提示:用戶名和密碼不能為空!', userName:'', psw:'' }) }else{ this.setData({ tip:'', userName:'用戶名:'+e.detail.value.userName, psw:'密碼:'+e.detail.value.psw }) } }, formReset:function(){ this.setData({ tip:'', userName:'', psw:'' }) } })
上面是我整理給大家的,希望今后會對大家有幫助。
相關文章:
在Mac中如何安裝nvm(詳細教程)
在微信小程序中如何實現時間功能
在webpack中有關生成代碼探索
在微信小程序中如何顯示單選項
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com