JavaScript-traversal IMG Fetch Current Click IMG Property

Source: Internet
Author: User

Hello everyone, the first time asked a little nervous, I small white, look forward to common progress with everyone. The problem is, I'm going through a group of IMG that I want to take to the subscript of the current click IMG, I added a num attribute on the IMG to get the key for that element, how do I get the current img num?

{foreach from=$answers item=item key=key }     {/foreach}这是遍历的img

//打印当前元素function selectImg(a){    console.log(a)}

I again Console.log (this.num) is undefined, all kinds of methods have been used, I now do not know how to obtain, seeking the guidance of the Great God.

Reply content:

Hello everyone, the first time asked a little nervous, I small white, look forward to common progress with everyone. The problem is, I'm going through a group of IMG that I want to take to the subscript of the current click IMG, I added a num attribute on the IMG to get the key for that element, how do I get the current img num?

{foreach from=$answers item=item key=key }     {/foreach}这是遍历的img

//打印当前元素function selectImg(a){    console.log(a)}

I again Console.log (this.num) is undefined, all kinds of methods have been used, I now do not know how to obtain, seeking the guidance of the Great God.

                

This.getattribute ("num");
Try this.

Principle does not understand, directly with JQ to the IMG tag binding a Click event, get this is you click on the IMG, want to get what you use This.getattribute ("attribute");

  • 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.