Easy to implement JavaScript image switching _javascript tips

Source: Internet
Author: User

This article examples for you to introduce JavaScript image switching implementation methods, share for everyone to reference, the specific content as follows

Effect Chart:

Web page to see a very common picture switching effect: Taobao, JD and other shopping, the introduction of the product will have more than one picture, is generally displayed, the bottom of a row of small pictures, the mouse into small pictures on the big picture will switch. Refer to Vivo x5m mobile 4G mobile phone. The following is a recording of the implementation process.

1. getElementById ()

This method is a very common method of manipulating DOM, such as having a P tag, the ID is set to PID, and the element can be manipulated by getElementById ("pid").

<! DOCTYPE html>
 
 

In the code above, a P tag is written in the body, the ID is PID, the onmouseover event is triggered when the mouse is positioned over the p tag, and the Changetext () method is executed to change the document within the P tag.

2. setattribute () and getattribute ()

The GetAttribute () method is used to get the value of a property, and the SetAttribute () method is used to assign a value to a property.

<! DOCTYPE html>
 
 

In the code above, there is a tag in the body that gets a label via getElementById (), and the value of Baiduurl.getattribute ("href") is the default href attribute, through Baiduurl.setattribute (" href "," http://www.taobao.com ") setting, the property value changes. Full code:

<! DOCTYPE html>  

Next Learn how to achieve local amplification, we have any good method? can be explored together.

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.