1 , Sessionstorage , Localstorage and the Cookies the difference between
Sessionstorage and Localstorage are HTML5 Web Storage APIs that can conveniently store data between Web requests.
Common denominator : all data stored on the browser side, and the same origin.
difference : Cookie data is always carried in the same-Origin HTTP request (even if not required), that is, the cookie is passed back and forth between the browser and the server. Sessionstorage and Localstorage do not automatically send data to the server and are saved locally only.
The cookie data also has the concept of path, which limits the cookie to only one path.
Storage size limits are also different. Cookie data cannot exceed 4k, and because each HTTP request carries a cookie, the cookie is only suitable for storing very small data, such as a session ID. Sessionstorage and Localstorage have a storage size limit, but are much larger than cookies and can reach 5M or larger.
Data is valid for different periods. Sessionstorage: Only valid until the current browser window is closed, it is naturally impossible to persist; Localstorage: Always valid, the window or browser Close is always saved, so it is used as persistent data; Cookies are valid until the cookie expiration time set , even if the window or browser is closed.
Scopes are different. Sessionstorage are not shared in different browser windows, even on the same page, localstorage are shared across all homologous windows, and cookies are shared across all homologous windows.
2 , JavaScript What are capture events and bubbling events?
Event bubbling refers to whether an object is nested when the underlying event is processed and passed to the upper object. Event bubbling is a step-by-step response to events in which events are propagated to ancestor elements by child elements, such as:
From Div-body-html-document,code:<div id= "divID" onclick= "click on Object" ></div>
Event capture is a method of processing when a specified event occurs, such as a mouse click, move, and so on, and event capture is to determine the source of the event layer by level, that is, the event is propagated from the ancestor element to the child element, for example:
From Document-html-body-div,code:document.getelementbyid ("divID")
In standard browsers such as Firefox, Chrome, and Safari, event propagation exists in the capture phase.
The AddEventListener for standard browsers has three parameters, AddEventListener (Type,fn,boolean), the first two parameters are not explained, and the third parameter, Boolean, determines whether the registration event occurs in the capture or bubbling phase , specifically as follows: true: Capture phase false: bubbling phase
3 , Ajax Transfer data asynchronously-page format
It's easy to use Ajax in the jquery framework first. When you import jquery.js, you load Ajax as soon as you enter the page
<script>
$.ajax ({
Type: "Post",
URL: ',//write ' xxxx.action '
Data: "//write the transfer parameters equivalent to the id=" ";
Success:function (msg) {
Alert (msg);//output data stream from the background
},
Error:function () {
Alert ("Loading failed ...")
}
});
</script>
Example:Java code
4 , JSON Data Interchange Format?
JSON has two types of structure:
1. A collection of name/value pairs (name/value). In different languages, it is understood as objects (object), recording (record), structure (struct), Dictionary (dictionary), hash table (hash table), keyed list (keyed list) or associative array (associative Array).
For example, JSON means "name/value pairs":
{"FirstName": "Brett"}
Create a record that contains multiple name/value pairs, such as:
{"FirstName": "Brett", "LastName": "McLaughlin", "email": "AAAA"}
2. Ordered list of values (an ordered list of values). In most languages, it is understood as an array (array). When you need to represent a set of values, JSON not only improves readability, but also reduces complexity.
For example, using JSON, you would simply group together several records with curly braces:
{"People": [
{"FirstName": "Brett", "LastName": "McLaughlin", "email": "AAAA"},
{"FirstName": "Jason", "LastName": "Hunter", "email": "BBBB"},
{"FirstName": "Elliotte", "LastName": "Harold", "email": "CCCC"}
]}
will be JSON assigning data to variables
For example, create a new JavaScript variable, and then assign the JSON-formatted data string directly to it:
var people = {"Programmers": [
{"FirstName": "Brett", "LastName": "McLaughlin", "email": "AAAA"},
{"FirstName": "Jason", "LastName": "Hunter", "email": "BBBB"},
{"FirstName": "Elliotte", "LastName": "Harold", "email": "CCCC"}
],
"Authors": [
{"FirstName": "Isaac", "LastName": "Asimov", "Genre": "Science Fiction"},
{"FirstName": "Tad", "LastName": "Williams", "Genre": "Fantasy"},
{"FirstName": "Frank", "LastName": "Peretti", "Genre": "Christian Fiction"}
],
"Musicians": [
{"FirstName": "Eric", "LastName": "Clapton", "instrument": "Guitar"},
{"FirstName": "Sergei", "LastName": "Rachmaninoff", "Instrument": "Piano"}
] }
Now people contains the data in the JSON format you saw earlier. However, the way data is accessed is not yet obvious.
accessing data
The long string above is really just an array, and after you put the array into a JavaScript variable, it's easy to access. In fact, you simply represent the array element with a dot notation. So, to access the last name of the first entry in the programmers list, just use the following code in JavaScript:
People.programmers[0].lastname;
Note that the array index is zero-based. So, this line of code first accesses the data in the people variable, then moves to the entry called programmers, then moves to the first record ([0]), and finally accesses the value of the LastName key. The result is a string value of "McLaughlin".
Here are a few examples of using the same variable.
People.authors[1].genre//value is "fantasy"
People.musicians[3].lastname//undefined
People.programmers[2].firstname//value is "Elliotte"
Convert back to String
Converting an object back to text format is simple in JavaScript:
String Newjsontext = people.tojsonstring ();
5 , with JS write the function, the largest number in the output array
function Getmaximin (arr,maximin) {
if (Maximin = = "Max") {
Return Math.max.apply (Math, arr);
}else if (Maximin = = "Min") {
Return Math.min.apply (Math, arr);
}
}
var a = [3,2,4,2,10]
var b = [12,4,45,786,9,78]
Alert ("AMax:" + getmaximin (A, "max") + "---aMin:" + getmaximin (A, "min") + "---bmax:" +getmaximin (b, "Max") + "---bmin:" + get Maximin (b, "Min")) //amax:10---amin:2---bmax:786---bmin:4
var max = Math.max.apply (math,values); Meaning executes the max function in the Math object, the parameter is values, and the return result is assigned to Max, where the Apply function is a JS built-in function that functions as the function and can only be called by the function.
The first argument in the Apply function is the object to which the function belongs, usually the current page (this). The second parameter is the array of arguments passed into the function (which must be arrays).
6 , JS The calling function returns an array, how to write the contents of the array in the page?
var arr= your array;
for (Var i=0;i<arr.length;i++)
{
$ ("#写的html位置的父节点ID"). Innerhtml=arr[i];
}
7 , with JS writing functions to implement string inversion
Method 1:
<script type= "Text/javascript" >
var str= "Abcdeg";
function Demo (str) {
Varstr2= "";
for (vari=0;i<str.length;i++) {
Str2+=str.charat (str.length-i-1);
}
document.write (str+ "<br/>" +STR2)
}
Demo (str);
</script>
Method 2:
<input type= "TextField" id= "input"/>
<div id= "Result" ></div>
<input type= "button" value= "reverse" onclick= "reverse ()"/>
<script language= "JavaScript" >
function reverse () {
Varstr=document.getelementbyid ("Input"). Value;
Vara=str.split (");
var result=newarray ();
while (A.length)
{
Result.push (A.pop ());
}
document.getElementById ("Result"). Innerhtml=result.join (");
}
</script>
--js part of true fusion treasure face question