JavaScript objects, arrays, and other parameters

Source: Internet
Author: User

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

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.