一種用 點+控件類名
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();