溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

小程序怎么獲取input標簽的值

發(fā)布時間:2021-05-18 11:10:34 來源:億速云 閱讀:238 作者:小新 欄目:移動開發(fā)

這篇文章將為大家詳細講解有關小程序怎么獲取input標簽的值,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

獲取微信小程序中input中的數(shù)據(jù)

<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通過后臺驗證跳轉(zhuǎn)
this.data.username獲取標簽中值-->
  var url = app.globalData.serverIp +"/user/login.html?"
  +"username="+this.data.username
  +"&password="+this.data.password;
  <!--為this賦值給全局對方法中調(diào)用-->
  var page=this;
  <!--用request進行后臺傳輸-->
  wx.request({
    url: url,
    success:function(response){
      var serverData=response.data;
      var status=serverData.status;
      var msg="登錄失敗";
      if(status==200){
        msg="登錄成功";
        //跳轉(zhuǎn)商場首頁navigateTo
        wx.navigateTo({
          url:"../storeindex/storeindex",
        })
         //把username保存到手機上
        //sync表示同步 setStorageSync函數(shù)的作用是同步保存數(shù)據(jù)相當于http中的cookie
        wx.setStorageSync("username", page.data.username);
      }
      wx.showToast({
        title: msg
      })
    },
    fail:function(e){
      console.log("聯(lián)網(wǎng)失敗");
      console.log(e);
    },
    
data: {
    username:"",
    password:""
  },
  usernameInput:function(e){
    this.data.username=e.detail.value;
  },
  passwordInput: function (e) {
    this.data.password = e.detail.value;
  },
  })
},

關于“小程序怎么獲取input標簽的值”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI