小程序如何获取input标签的值

 4353

本篇文章给大家介绍一下微信小程序获取input标签值的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。


小程序如何获取input标签的值


获取微信小程序中input中的数据

  1. <scroll-view>
  2.     <view id='titleView'>
  3.         <text id="titleText">登录</text>
  4.     </view>
  5.     <view id='mainView'>
  6.         <text>用户名</text>
  7.         <input class='input' bindinput='usernameInput'></input>
  8.         <text>密码</text>
  9.         <input class='input' bindinput='passwordInput'></input>
  10.         <button class="btn" bindtap='login'>登录</button>
  11.         <button class='btn' bindtap='toRegister'>注册</button>
  12.     </view>
  13. </scroll-view>

登录的js页面

  1. var app=getApp();
  2. Page({
  3. login:function(e){
  4. <!--拼接url通过后台验证跳转
  5. this.data.username获取标签中值-->
  6.     var url = app.globalData.serverIp +"/user/login.html?"
  7.     +"username="+this.data.username
  8.     +"&password="+this.data.password;
  9.     <!--为this赋值给全局对方法中调用-->
  10.     var page=this;
  11.     <!--用request进行后台传输-->
  12.     wx.request({
  13.         url: url,
  14.         success:function(response){
  15.             var serverData=response.data;
  16.             var status=serverData.status;
  17.             var msg="登录失败";
  18.             if(status==200){
  19.                 msg="登录成功";
  20.                 //跳转商场首页navigateTo
  21.                 wx.navigateTo({
  22.                     url:"../storeindex/storeindex",
  23.                 })
  24.                 //把username保存到手机上
  25.                 //sync表示同步 setStorageSync函数的作用是同步保存数据相当于http中的cookie
  26.                 wx.setStorageSync("username", page.data.username);
  27.             }
  28.             wx.showToast({
  29.                 title: msg
  30.             })
  31.         },
  32.         fail:function(e){
  33.             console.log("联网失败");
  34.             console.log(e);
  35.         },
  36.          
  37.         data: {
  38.             username:"",
  39.             password:""
  40.         },
  41.         usernameInput:function(e){
  42.             this.data.username=e.detail.value;
  43.         },
  44.         passwordInput: function (e) {
  45.             this.data.password = e.detail.value;
  46.         },
  47.     })
  48. },


本文网址:https://www.zztuku.com/detail-8878.html
站长图库 - 小程序如何获取input标签的值
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐