Javascript-traverse img to get the img attribute of the current click

Source: Internet
Author: User
Hello everyone. I am a little nervous when I ask a question for the first time. I hope to make progress together with you. The problem is that I traverse a group of img and want to obtain the subscript of the currently clicked img. I added a num attribute to img to get the key of this element, how can I obtain the num of the current img? {Code...

Hello everyone. I am a little nervous when I ask a question for the first time. I hope to make progress together with you. The problem is that I traverse a group of img and want to obtain the subscript of the currently clicked img. I added a num attribute to img to get the key of this element, how can I obtain the num of the current img?

{Foreach from = $ answers item = item key = key} {/foreach} This is the img of traversal

// Print the current element function selectImg (a) {console. log ()}

I again use the console. log (this. num) as undefined, and all the methods have been used. I don't know how to get it now. please kindly advise.

Reply content:

Hello everyone. I am a little nervous when I ask a question for the first time. I hope to make progress together with you. The problem is that I traverse a group of img and want to obtain the subscript of the currently clicked img. I added a num attribute to img to get the key of this element, how can I obtain the num of the current img?

{Foreach from = $ answers item = item key = key} {/foreach} This is the img of traversal

// Print the current element function selectImg (a) {console. log ()}

I again use the console. log (this. num) as undefined, and all the methods have been used. I don't know how to get it now. please kindly advise.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.