Need to get image tag in wechat mini program

201 views Asked by At

I'm trying to get the image src from wxml. All of the image src should be obtained and replaced.

What should replace document.getElementsByTagName in Wechat Mini?

2

There are 2 answers

4
huoguo32 On

js: var that = this;

    var query = wx.createSelectorQuery();
    
    query.select('.classname').boundingClientRect(function (params) {
        cosnole.log(params)
    })
0
huoguo32 On

As for your original question, perhaps you could use a "custom property" (data-xxx) to get your src

<image src="{{src}}" data-src="{{src}}" bindtap="ontap" />
js:
Page({
    data: {
        src:'1.jpg'
    },
 
    ontap:function(e) {
        const {src} = e.currentTarget.dataset;
        console.log(src);
    }
})