Example: The value of the character information passed into the function for processing.
The simplification is as follows:
CSS Section
#wrap {
width:100px;
Background: #0f0;
}
HTML Section
<div id= "Wrap" ></div>
js Section
1. Object-Pass Reference
var owrap = document.getElementById (' wrap ');
var objs1 = {
"Name": "Zack",
"Age": "23",
"Gender": "Male"
}
or the parameter name is not quoted.
* Note that the standard JSON format is enclosed in double quotes, separated by commas *
var objs1 = {
Name: "Zack",
Age: "23",
Gender: "Male"
// }
function fn1 (obj) {
var a = document.createelement ("div");
var B = document.createelement ("div");
var c = document.createelement ("div");
Owrap.appendchild (a);
Owrap.appendchild (b);
Owrap.appendchild (c);
a.innerhtml = Obj.name;
b.innerhtml = Obj.age;
c.innerhtml = Obj.gender;
}
FN1 (OBJS1);
2. Array-pass parameter
Note the parameter order
var = ["Muler", "objs2", "male"];
function fn2 (obj) {
var a = document.createelement ("div");
var B = document.createelement ("div");
var c = document.createelement ("div");
Owrap.appendchild (a);
Owrap.appendchild (b);
Owrap.appendchild (c);
a.innerhtml = obj[0];
b.innerhtml = obj[1];
c.innerhtml = obj[2];
}
FN2 (OBJS2);
3. Transfer of non-quantitative parameters
The arguments represented by a function with a formal parameter name
Pay attention to the argument order when calling
function Fn3 () {
var a = document.createelement ("div");
var B = document.createelement ("div");
var c = document.createelement ("div");
Owrap.appendchild (a);
Owrap.appendchild (b);
Owrap.appendchild (c);
a.innerhtml = Arguments[0];
b.innerhtml = arguments[1];
c.innerhtml = arguments[2];
}
Fn3 ("Rosa", "$", "female");
JavaScript objects, arrays, and other parameters