1. List the names of object attributes
<script language="javascript">
var obj=new Object();
obj.a="Hello, I am Tian Hongchuan";
obj.b="You are Tian Hongchuan, what a big deal?";
obj.c="Xixi, haha, I am attribute c";
//Of course the above is to declare a new object, declare attributes to the object and then assign values.
// Next we will make a nested object for the above object, or add new attributes and assign values
obj.d=new Object();
obj.d.aa="I am the boss of the sub-object";
obj.d.bb="Then of course I can only be the second child, eh? Second child? Dizzy";
list(obj)//Call the following function to list the attribute names of the object
function list(obj)
{//Note that this method cannot read predefined attribute names?
var name=""; //Set an empty variable
for(var i in obj) //Variable I loops in the obj object. This line cannot be quoted.
name +=i+"n" //Call the value read by i to the name variable
alert(name);//display name
}
</script>
2: The usage object www.cnblogs.com/thcjp/ will continue to add js-ajax entry examples in the near future.
<script language="javascript">
var obj=new Object();
obj.a="Hello, I am Tian Hongchuan";
obj.b="You are Tian Hongchuan, what a big deal?";
obj.c="Xixi, haha, I am attribute c";
//Of course the above is to declare a new object, declare attributes to the object and then assign values.
// Next we will make a nested object for the above object, or add new attributes and assign values
obj.d=new Object();
obj.d.aa="I am the boss of the sub-object";
obj.d.bb="Then of course I can only be the second child, ah, ah? Second child? Dizzy";
//Let's read it out and take a look
alert("The first line is of course: "+obj.a+"nt The second line is "+
obj.b+"nt三是"+obj.c);
//We are bored below, so let’s change the pop-up one, but the effect is the same.
confirm("I am: "+obj.d.aa+"n Do you see it? The following line is: "+obj.d.bb);
//Note that /n above is a line break and t is the displayed alignment format.
</script>
3: Simple examples of using functions www.cnblogs.com/thcjp/ will continue to add js-ajax introductory examples in the near future
<script language="javascript">
// Below we define some functions as methods
function add(x,y){return x+y;}
function jian(x,y){return xy;}
function chen(x,y){return x*y;}
function chu(x,y){return x/y;}
//Define another function that can take the above function as a parameter
function oper(op1,op2,op3)
{//Pass in three parameters
return op1(op2,op3);//Recombine the three parameters for multiple calls
}
var i=oper(add, oper(add,2,3), oper(jian,5,4));//Simply speaking, the result reflected by this sentence is (2+3 + 5-4)
//The above sentence may seem a bit weird, but it actually calls the oper function and assigns it three parameters, but with additional nesting.
document.write("The result of the oper method is: <b>"+i+"<b>");//This sentence is a sentence from reality, and the following I is bolded
</script>
4; Loop, judge www.cnblogs.com/thcjp/ will continue to add js-ajax entry examples in the near future
<script language="javascript">
for(var i=0,fact=1,b=1;i<10;i++,fact*=i,b+=fact)
{//Declare an i, fact, b and then do the assignment operation. i is incremented by 1, fact is multiplied by the incremented i, and b is added to the resulting fact.
document.write(i+"="+fact+"="+b+"<br>");
//Display i = fact = b and add a newline to display the result of the next cycle
}
</script>
<script language="javascript">
var name="Sister Mei";//If the value here is equal to null, the following will display Hello Brother A Chuan
var s="Hello a"+((name!=null) ? name : "Brother Chuan");//This sentence is actually an ifelse judgment statement, but it is simplified with ?
alert(s);//A dialog box pops up, only OK
confirm(s);//Confirm or cancel
</script>