js| Objects | functions | loops
1, enumerate the names of the object properties
<script language= "JavaScript" >
var obj=new Object ();
Obj.a= "Hello, I am Tianhongkun";
Obj.b= "What are You, Tianhongkun?" ";
Obj.c= "cc, haha, I am attribute C";
The above, of course, is to declare a new object and give the object the attribute to be assigned again
Let's do a set of objects for the above object, or add a new attribute and assign a value
Obj.d=new Object ();
Obj.d.aa= "I am the eldest of the child's object";
Obj.d.bb= "Then of course I can only do the penis, alas, ah?" Dick Halo ";
List (obj)//Call the following function to enumerate the property names of the object
Function list (obj)
{//Note that this method cannot read the predefined property names?
var name= "";//set an empty variable
for (var i in obj)//variable I loops in obj object, this line cannot be quoted
name +=i+ "\ n"///The value I read to the name variable
alert (name);//Show name
</script
2: Using object www.cnblogs.com/thcjp/will continue to increase in the near future Js-ajax Getting started instance
<script language= "javascript"
var obj=new Object ();
obj.a= "Hello, I am Tianhongkun";
Obj.b= "What are You, Tianhongkun?" ";
obj.c= "cc, haha, I am attribute C";
//The above, of course, is to declare a new object, and to declare the object to assign a value
///below we'll make a set object for the above object, or add a new attribute and assign a value of
Obj.d=new object ();
Obj.d.aa= "I am the eldest of the child's object";
obj.d.bb= "Then of course I can only do the penis, alas, ah?" Dick Halo ";
//Below we read out to see
alert ("The first line is of course:" +obj.a+ "\n\t the second is" +
obj.b+ "\n\ T three is "+OBJ.C";
//Below we are bored, change a popup hehe, but the effect is the same
confirm ("I am:" +obj.d.aa+ "\ n) See? The downside is: "+OBJ.D.BB";
//Note the above/n is a newline, \ t is the displayed alignment
</script>
3: A simple instance of the function www.cnblogs.com/thcjp/will be increasing in the near future Js-ajax Getting started instance
< Script language= "javascript"
//below we define some functions as methods
Function Add (x,y) {return x+y;}
Function Jian (x,y) {return x-y;}
function Chen (x,y) {return x*y}
function Chu (x,y) {return x/y;}
And then define a function that can take the above function as an argument.
function oper (OP1,OP2,OP3)
{//Incoming three parameters
return OP1 (OP2,OP3);//Add three parameters to the new group for multiple calls
}
var i=oper (Add, Oper (add,2,3), Oper (jian,5,4));//The result of this sentence is (2+3 + 5-4)
The above sentence seems to be more Rao, in fact, call the Oper function and give three parameters, just a set of
document.write ("Oper method results in: <b>" +i+ "<b>");/This is the truth has been a word, the back of I Bold
</script>
4. Cycling, judging www.cnblogs.com/thcjp/will continue to increase in the near future Js-ajax examples of getting Started
<script language= "JavaScript" >
for (Var i=0,fact=1,b=1;i<10;i++,fact*=i,b+=fact)
{//Affirm a i,fact,b after the assignment operation I increment 1,fact times the increment i,b add the result fact
document.write (i+ "=" +fact+ "=" +b+ "<br>");
Show i = fact = B Plus line shows the results of the next loop
}
</script>
<script language= "JavaScript" >
var name= "Mei elder sister";/if the value here equals NULL, the following will show you hello a brother Chuan
var s= "Hello a" + ((name!=null)? Name: "Chuan elder brother");/This sentence is actually a ifelse judgment statement, just use? Simplifies the
alert (s);//Bounce a dialog box out, only OK
Confirm (s);/Be sure and cancel
</script>