checkbox怎么在微信小程序中使用

checkbox怎么在微信小程序中使用?針對這個(gè)問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡單易行的方法。

我們提供的服務(wù)有:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、賓川ssl等。為上1000家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的賓川網(wǎng)站制作公司

type_add.js

// pages/detail_add/detail_add.js
Page({

 /**
  * 頁面的初始數(shù)據(jù)
  */
 data: {
  selectData: "", //下拉列表的數(shù)據(jù)
  height: 20,
  focus: false
 },
 checkboxChange: function(e) {
  console.log('checkbox發(fā)生change事件,攜帶value值為:', e.detail.value)
  console.log("長度:" + e.detail.value.length);
  this.setData({
   typeId: e.detail.value,
   length: e.detail.value.length
  })


 },
 formSubmit: function(e) {
  console.log('form發(fā)生了submit事件,攜帶數(shù)據(jù)為:' + e.detail.value.amount + ", " + e.detail.value.typeId + ", " + this.data.remark + ", " + this.data.date + ", " + this.data.time);

  var amount = e.detail.value.amount;
  var typeId = this.data.typeId;

  var date = this.data.date;
  var time = this.data.time;
  var remark = e.detail.value.remark;
  var createDate = date + " " + time;
  var length = this.data.length;
  console.log("length:" + length);
  console.log("date:" + date);
  console.log("time:" + time);
  console.log("createDate:" + createDate)

  if (amount == null || amount == "") {
   wx.showToast({
    title: "支出金額不能為空",
    icon: 'none',
    duration: 1500
   })
  } else if (typeId == null || typeId == "") {
   wx.showToast({
    title: "支出類型不能為空",
    icon: 'none',
    duration: 1500
   })

  } else if (length >= 2) {
   wx.showToast({
    title: "支出類型只能選擇一種",
    icon: 'none',
    duration: 1500
   })
  } else if (date == null || date == "") {
   wx.showToast({
    title: "日期不能為空",
    icon: 'none',
    duration: 1500
   })
  } else if (time == null || time == "") {
   wx.showToast({
    title: "時(shí)間不能為空",
    icon: 'none',
    duration: 1500
   })
  } else if (remark == null || remark == "") {
   wx.showToast({
    title: "備注不能為空",
    icon: 'none',
    duration: 1500
   })
  } else {



   wx.request({

    url: getApp().globalData.urlPath + "spendingDetail/add",
    method: "POST",
    data: {
     amount: amount,
     typeId: typeId,
     createDate: createDate,
     remark: remark
    },
    header: {
     "Content-Type": "application/x-www-form-urlencoded"
    },
    success: function(res) {
     console.log(res.data.code);
     if (res.statusCode == 200) {

      //訪問正常
      if (res.data.code == "000000") {
       wx.showToast({
        title: "添加支出詳情成功",
        icon: 'success',
        duration: 3000,
        success: function() {

         wx.navigateTo({
          url: '../detail/detail'
         })
        }
       })

      }
     } else {

      wx.showLoading({
       title: '系統(tǒng)異常',
       fail
      })

      setTimeout(function() {
       wx.hideLoading()
      }, 2000)
     }

    }
   })
  }


 },
 formReset: function() {
  console.log('form發(fā)生了reset事件')
 },
 bindDateChange: function(e) {
  console.log('picker發(fā)送選擇改變,攜帶值為', e.detail.value)
  this.setData({
   date: e.detail.value
  })
 },
 bindTimeChange: function(e) {
  console.log('picker發(fā)送選擇改變,攜帶值為', e.detail.value)
  this.setData({
   time: e.detail.value
  })
 },
 /**
  * 生命周期函數(shù)--監(jiān)聽頁面加載
  */
 onLoad: function(options) {
  wx.setNavigationBarTitle({

   title: "添加支出詳情"

  })


  var userCode = wx.getStorageSync('userId').toString();
  var self = this;
  wx.request({
   url: getApp().globalData.urlPath + "spendingType/types", //json數(shù)據(jù)地址 
   data: {
    userCode: userCode
   },
   headers: {
    "Content-Type": "application/x-www-form-urlencoded"
   },
   success: function(res) {
    console.log("res.data.data.typeName:" + res.data.data)

    self.setData({

     selectData: res.data.data

    })


   }
  })
 },

 /**
  * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成
  */
 onReady: function() {

 },

 /**
  * 生命周期函數(shù)--監(jiān)聽頁面顯示
  */
 onShow: function() {

 },

 /**
  * 生命周期函數(shù)--監(jiān)聽頁面隱藏
  */
 onHide: function() {

 },

 /**
  * 生命周期函數(shù)--監(jiān)聽頁面卸載
  */
 onUnload: function() {

 },

 /**
  * 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作
  */
 onPullDownRefresh: function() {

 },

 /**
  * 頁面上拉觸底事件的處理函數(shù)
  */
 onReachBottom: function() {

 },

 /**
  * 用戶點(diǎn)擊右上角分享
  */
 onShareAppMessage: function() {

 }
})

type_add.wxml:

<form bindsubmit="formSubmit" bindreset="formReset">
 <view class="section">
  <text>支出金額</text>
  <input name="input" name="amount" placeholder="請輸入支出金額" />
 </view>

 <view class="section">
  <text>支出類型</text>
  <checkbox-group bindchange="checkboxChange">
   <label class="checkbox" wx:for="{{selectData}}">
    <checkbox value="{{item.typeId}}" checked="{{item.checked}}" />{{item.typeName}}
   </label>
  </checkbox-group>

 </view>

 <view>
  <text>創(chuàng)建時(shí)間</text>
  <view class="section">
   <picker mode="date" value="{{date}}" start="2018-09-01" end="2030-09-01" bindchange="bindDateChange">
    <view class="picker">
     選擇日期: {{date}}
    </view>
   </picker>
  </view>
  <view class="section">
   <picker mode="time" value="{{time}}" start="00:00=" end="23:59" bindchange="bindTimeChange">
    <view class="picker">
     選擇時(shí)間: {{time}}
    </view>
   </picker>
  </view>
 </view>
 <view class="section">
  <text>備注</text>
  <input name="input" name="remark" placeholder="請輸入備注" />
 </view>
 <view>
  <text>\n</text>
 </view>
 <view class="btn-area">
  <button form-type="submit">提交</button>
  <view>
   <text>\n</text>
  </view>
  <button form-type="reset">重置</button>
 </view>
</form>

bindchange=”checkboxChange” 相當(dāng)于js中的onchange事件。

上述中的form表單基本就是參考官方文檔改的。

有一段代碼還是要提一下:

self.setData({
  selectData: res.data.data
 })

self其實(shí)相當(dāng)于this,意為當(dāng)前。每次觸發(fā)事件,對應(yīng)的值都會(huì)進(jìn)行存儲(chǔ),用于與后臺(tái)通信進(jìn)行數(shù)組傳遞,

type_add.wxss:

/* pages/login/login.wxss */
form{
 width: 310px;
 height: 240px;
 line-height: 40px;
 /* border: 1px solid red; */
}
input{
 border: 1px solid #ccc;
 width: 310px;
 height: 40px;
}
.button{
 margin-top: 20px;
}
.header text{
 font-size: 25px;
 color: #666;
}
form text{
 font-size: 20px;
 color: #666;
}

關(guān)于checkbox怎么在微信小程序中使用問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。

文章名稱:checkbox怎么在微信小程序中使用
網(wǎng)頁鏈接:http://www.muchs.cn/article38/ishjpp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、App設(shè)計(jì)、網(wǎng)站排名、虛擬主機(jī)、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)