小程序在js里獲取控件的兩種方式


一種用 點+控件類名

var query = wx.createSelectorQuery();
    //選擇id
    var that = this;
    query.select('.progressBarCarrier').boundingClientRect(function (rect) {
      let width = rect.width
      console.log("矩形:" + JSON.stringify(rect))
      let setpWidth = width / 25
      // console.log("空你感覺:" + setpWidth)
      that.setData({
        stepWidth: setpWidth
      })
    }).exec();

 

另外一種用 #+控件id

 

        let option = answers[idx]
        let optionName = "#opt" + bigIdx+idx
       
        var query = wx.createSelectorQuery();
        //選擇id
        var that = this;
        query.select(optionName).boundingClientRect(function (rect) {
          let height = rect.height
          console.log("選項尺寸:" + JSON.stringify(rect))

          option.borderRadius = height
          console.log("選項字典:" + JSON.stringify(questions))
          that.setData({
            questionList: questions
          })
        }).exec();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM