JavaScript Statements
With statement: (object manipulation statement)
Function: Establishes a default object for a program.
Format:
With (< object >) {
< statement groups >
}
1<body>2<!--don't write the document in front of each write--3<script type= "Text/javascript" >4 With (document) {5Write ("<ol>");6Write ("<li>hello</li>")7Write ("<li>wolrd</li>")8Write ("<li>hello world</li>")9Write ("</ol>");Ten } One</script> A</body>
For...in statement: Repeatedly executes all properties of the specified object
Format:
For (variable in object) {
< statement groups >
}
1<body>2<script type= "Text/javascript" >3function member (name, gender) {//do not add Var, like the constructor of a class4 This. Name =name;5 This. Gender =gender;6 }7 function Showproperty (obj, objstring) {8var str = "";9 for(var i in obj)//iterating through each of the properties in obj, I can be seen as the name of the property, Obj[i] represents the value of the propertyTenstr + = objstring + "." +I+ "=" + Obj[i] + "<BR>"; One returnstr; A } -obj =NewMember ("Andy Lau", "Boy");//creating an object instance obj -document.write (Showproperty (obj, "person")) the</script> -</body>
Operation Result:
1 person.name = Andy Lau 2 person.gender = male
Object
Default Object – Date Object
Format: Date Object name =new date ([date parameter])
Date Parameters:
1. Omit (most commonly used);
2. English-numeric format: Month day, A.D. year [hours: minutes: seconds]
such as: Today=new Date ("october1,2008 12:00:00")
3. Numerical format: A.D., month, day, [hours, minutes, seconds]
such as: Today=new Date (2008,10,1)
1<script type= "Text/javascript" >2var date =NewDate ();3var day =Date.getday ();4 if(day==0){5Day = "Days";6 }7Document.writeln ("Now Time:" + (Date.getyear () +1900) + "year" + (Date.getmonth () +1) + "Month"8+date.getdate () + "Day" + "Week" +day+ "" +date.gethours () + ":" +date.getminutes ()9+":"+date.getseconds ())Ten</script>
Array object;
To create an array object:
Format 1: Array object name =new array ([number of elements])
Format 2: Array object name =new array ([[element 1][, Element 2, ...])
Format 3: Array object name =[element 1[, Element 2, ...]
1<body>2<script type= "Text/javascript" >3 //var fruit = new Array ("Apple", "pear", "orange");4 //var fruit=["Apple", "pear", "orange";//Recommended Use5var fruit =NewArray ();6Fruit.push ("Apple");7Fruit.push ("Pear");8Fruit.push ("Orange");9Fruit.push ("Banana");TenFruit.push ("Watermelon"); One for(Var i=0;i<fruit.length;i++){ ADocument.writeln ("fruit[" +i+ "]" + "=" +fruit[i]+ "<br/>"); - } -</script> the</body>
Anatomy of how JavaScript objects are defined