Hello everyone, I am a little nervous to ask questions for the first time. I am a novice and hope to make progress together with everyone. The problem is this. I traverse a group of img and want to get the subscript of the currently clicked img. I added a num attribute to the img to get the key of the element. How should I get the num of the current img?
<code>{foreach from=$answers item=item key=key } <img src="{$item.img}" num="{$key}" onclick="selectImg(this)" class="funny-img" style=" width: 23%;margin: 0 1% 4% 1%;float: left; opacity: 0.6;"> {/foreach} 这是遍历的img</code>
<code> //打印当前元素 function selectImg(a){ console.log(a) } </code>
I found that console.log(this.num) is undefined. I have used various methods. Now I don’t know how to get it. Please give me some guidance.