Javascrip--dom operation (Property manipulation)

Source: Internet
Author: User

Attribute

A.setattribute ("Property name", "property value")--set property
A.getsttribute ("Property name")--get property
A.removeattribute ("Property name")--Remove attribute

To illustrate:

Example 1: Do a question, if the input answer is correct then pop up correctly, error pop-up error;

Here in text write a Daan attribute, which stored the value of the answer, click to check the answer when Cheak input and answer whether the same:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">which year was the Republic of China founded? <input type= "Text" daan= "1912" id= "T1" value= ""/> <!--value: Default--><input type= "button" onclick= "Check ( ) "value=" Check the answer "/></form></body>functionCheck () {varA=document.getelementbyid ("T1"); vara1=a.value;<!--define the variable A1 to get the value of the input-varA2=a.getattribute ("Daan");<!--Get Properties--if(a1==A2) {Alert ("Congratulations on your answer!" "); }    Else{alert (Fool "); }    }</script>

Results:

When you enter the correct answer

When you enter the wrong answer

Example 2: The Consent button, countdown 10 seconds, the consent button becomes available, here is the Action property: Disable, to change the state of the button, when disabled= "disabled" button is not available.

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">#b1 {width:80px;    height:30px; } //Set the properties of the button </style>varn=10;varA=document.getelementbyid ("B1");functionBian () {n--; if(n==0) {A.removeattribute ("Disabled"); A.value= "Agree"; return; }Else{A.value= "Consent" ("+n+") "; Window.settimeout ("Bian ()", 1000);} }window.settimeout ("Bian ()", 1000); </script>

Javascrip--dom operation (Property manipulation)

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.