"HTML5" uses scripting to control the use of the details element of the interaction element

Source: Internet
Author: User

1. Source Code

<!DOCTYPE HTML  Public"-// the//DTD XHTML 1.0 Transitional//EN" "http://www.W3.org/TR/XHTML1/DTD/xhtml1-transitional.DTD"><HTML xmlns="http://www.W3.org/1999/XHTML"><Head><Meta http-equiv="Content-type"content="text/HTML;CharSet=Utf-8"/><title>scripting controls Interactive elements</title></Head><Body><span OnClick="Span1_Click() ">footnotes</span><Details ID="DETIALS1">This page was generated on September 20, 2017</Details><Script type="text/JavaScript">//controls whether content is displayed based on attributesfunction Span1_Click(){var OBJD = document.getElementById ("detials1");var ATTD = Objd.getattribute ("open");if(ATTD! = "Open") {Objd.setattribute ("open", "open");}Else{OBJD.RemoveAttribute("Open");}} </Script></Body></HTML>
View Code

2. Page effects

2.1 Click the footnote before

2.2 Click the footnote after

In JavaScript, use the GetAttribute () method to get the "open" property of the <details> element and then determine the attribute value of the element, and when the value is "open", use the RemoveAttribute () method to delete the < The "open" property of the details> element, or vice versa, using the setattribute () method to increase the property.

"HTML5" uses scripting to control the use of the details element of the interaction element

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.