小程序获取input标签值有哪些技巧?
发布时间:2022-07-09 13:49:33 所属栏目:经验 来源:互联网
导读:获取微信小程序中input中的数据 scroll-view view id=titleView text id=titleText登录/text /view view id=mainView text用户名/text input class=input bindinput=usernameInput/input text密码/text input class=input bindinput=passwordInput/input but
获取微信小程序中input中的数据 <scroll-view> <view id='titleView'> <text id="titleText">登录</text> </view> <view id='mainView'> <text>用户名</text> <input class='input' bindinput='usernameInput'></input> <text>密码</text> <input class='input' bindinput='passwordInput'></input> <button class="btn" bindtap='login'>登录</button> <button class='btn' bindtap='toRegister'>注册</button> </view> </scroll-view> 登录的js页面 var app=getApp(); Page({ login:function(e){ <!--拼接url通过后台验证跳转 this.data.username获取标签中值--> var url = app.globalData.serverIp +"/user/login.html?" +"username="+this.data.username +"&password="+this.data.password; <!--为this赋值给全局对方法中调用--> msg="登录成功"; //跳转商场首页navigateTo wx.navigateTo({ url:"../storeindex/storeindex", }) //把username保存到手机上 //sync表示同步 setStorageSync函数的作用是同步保存数据相当于http中的cookie wx.setStorageSync("username", page.data.username); } wx.showToast({ title: msg }) }, fail:function(e){ console.log("联网失败"); console.log(e); usernameInput:function(e){ this.data.username=e.detail.value; }, passwordInput: function (e) { this.data.password = e.detail.value; }, }) }, (编辑:开发网_开封站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |