The realization principle of Web page skin-changing effect

Source: Internet
Author: User

Effect principle:

Prepare several sets of CSS style sheets

Tune each CSS style sheet for compatibility

When clicking the button, change the value of the href in link (JS gets the link tag, the value of the href is changed by JS, Link can also give its ID)

HTML and JS:

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title><LinkID= "Link1"href= "Css1.css"rel= "stylesheet"type= "Text/css" /></Head><Body><DLID= "message">    <form>        <DT>            <Strong>You can change the skin of the submission box:</Strong>            <inputID= "BTN1"type= "button"value= "Skin 1"  />            <inputID= "BTN2"type= "button"value= "Skin 2"  />        </DT>        <DD>Enter your name:<inputclass= "text"type= "text" /></DD>        <DD>Enter Password:<inputclass= "text"type= "Password" /></DD>        <DD>Please leave your message:<textarea></textarea></DD>        <DDclass= "Center"><inputclass= "BTN"type= "Submit"value= "Submit" /></DD>    </form></DL></Body><Scripttype= "Text/javascript">    if(document.getElementById) {btn1=document.getElementById ("BTN1"); BTN2=document.getElementById ("btn2"); Link1=document.getElementById ("Link1"); Btn1.onclick=function() {link1.href="Css1.css"; } Btn2.onclick=function() {link1.href="Css2.css"; }    }Else{alert ("Browser not compatible, please replace"); }</Script></HTML>

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.