js--Action Properties

Source: Internet
Author: User

Action Properties:

Object. SetAttribute (' attribute name ', ' value '); -Add attributes
Object. getattribute (' attribute name '); -Gets the property value, if no this property, then returns null

<! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Content-type"Content="text/html; Charset=utf-8"/> <title></title> <style type="Text/css">. div1 {width:100px;            height:50px; float: Left; Margin-right:10px; }    </style>class="Div1"Dd="1"></div> <divclass="Div1"Dd="1"></div> <divclass="Div1"Dd="0"></div> <divclass="Div1"Dd="0"></div> <divclass="Div1"></div> <divclass="Div1"></div></body>"Text/javascript">varAA = Document.getelementsbyclassname ("Div1");  for(vari =0; i < aa.length; i++) {        if(Aa[i].getattribute ("DD") =="1") Aa[i].style.backgroundcolor="Green"; Else if(Aa[i].getattribute ("DD") =="0") Aa[i].style.backgroundcolor="Yellow"; ElseAa[i].style.backgroundcolor="Red"; }</script>


Object. removeattribute (' attribute name '); -Remove attributes

<! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Content-type"Content="text/html; Charset=utf-8"/> <title></title>"Button"Value="Button 111"Id="DD1"/> <input type="Button"Value="Button 222"Id="DD2"/></body>"Text/javascript">varAAA = document.getElementById ("DD1"); varBBB = document.getElementById ("DD2"); //Click events for button 111Aaa.onclick =function () {//Button 111 Adding a property is not available         This. SetAttribute ("Disabled","Disabled"); //gets the value of the property value in AAA        varCCC = This. getattribute ("value");    Alert (CCC); }    //BBB's Click eventBbb.onclick =function () {//Remove the AAA disabled propertyAaa.removeattribute ("Disabled"); }</script>

2. Verify 5+5=?

<! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Content-type"Content="text/html; Charset=utf-8"/> <title></title>5+5= <input type="text"Id="DD1"Data="Ten"/> <input type="Button"Id="DD2"Value="Validation"/></body>"Text/javascript">varAAA = document.getElementById ("DD1"); varBBB = document.getElementById ("DD2"); //Click events for button 111//BBB's Click eventBbb.onclick =function () {vartxt = Aaa.getattribute ("Data"); if(txt = =aaa.value) Alert ("correct"); ElseAlert ("Stupid"); }</script>


Timer:
Window.settimeout (function () {}, time interval milliseconds);
-Time bomb, deferred execution, only once

Window.setinterval (function () {}, Interval of time milliseconds);
-infinite loops, each cycle has a time interval, generally not less than 20 milliseconds
-It has a return value, you can use a variable to receive the Timer object

Window.clearinterval (the Timer object to be closed);
Once this code is executed, the execution of this timer object is stopped immediately.

Object. offsetwidth

js--Action Properties

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.