小程序在js里获取控件的两种方式

一种用 点+控件类名

var query = wx.createSelectorQuery();
    //选择id
    var that = this;
    query.select('.progressBarCarrier').boundingClientRect(function (rect) {
      let width = rect.width
    console.log("矩形:",rect)
     
    }).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();

 

posted on 2020-03-20 10:33  土匪7  阅读(1831)  评论(0编辑  收藏  举报