1.js event bubbling and blocking methods:
The concept of event bubbling:
Fires a class of events on an object (such as clicking the OnClick event), and if this object defines a handler for this event, then this event invokes the handler, and if the event handler is not defined or the event returns true, the event propagates to the object's parent object, from inside to outside, Until it is processed (all the same events of the parent object will be activated), or it reaches the topmost level of the object, the Document object (some browsers are windows).
In other words, that is, if the event of the child class object is activated, then the same event of the parent object is activated and executed in the order in which the subclass object has been extended outward. For example, the following code:
<div onclick= "Outsidework ()" id= "OutSide" style= "width:100px; height:100px; Background: #000; padding:50px "> <div onclick=" insidework () "id=" InSide "style=" width:100px; height:100px; background: #CCC " ></div></div> <script type= "Text/javascript" > function outsidework () { alert (' My name is outside,i be working ... '); } function insidework () { alert (' My name is inside,i be working ... '); } // bubbling allows both large boxes and small boxes to be ordered and executed in order from inside to outside </script>
The code that blocks the event bubbling is as follows, passing in the event object and calling the Stoppropagation method, which is optimized for different browsers:
functionDemo (id,e) {alert (ID); Stopbubble (e); } functionstopbubble (e) {if(e && e.stoppropagation) {//determine if there is stoppropagation attributeE.stoppropagation ();//Stop Spreading } Else{window.event.cancelBubble=true; } }</script>2. Cross-page communication frameset How the internal pages interact:
Window.frames returns all named frames in the window
Parent (if the window is a top-level window, then Parent==self==top)
Top is the top-level parent window (some windows have several layers of frameset or IFRAME)
Self is the current window (equivalent Windows)
Window.opener returns the window that opens the current window with the Open method
3.JSON
- The syntax rules for JSON: arrays are denoted by [], objects are represented by {}, names. Value pairs make up an array object. The name is placed in double quotation marks, with values such as strings, values, Boolean values, NULL, objects, and arrays. The values are separated by objects.
To serialize a JSON object:
var xiaoming = { ' xiaoming ', +, true, 1.65, NULL , ' Middle-school ': ' \ ' w3c\ ' Middle School ', skills: [' JavaScript ', ' Java ', ' Python ', ' Lisp ' // ' {' name ': ' Xiaoming ', ' age ': +, ' gender ': true, ' height ': 1.65, ' grade ': null, ' middle-school ': ' \ ' w3c\ ' Middle school ', ' Skills ": [" JavaScript "," Java "," Python "," Lisp "]} '
The second parameter can be used to output the specified properties of an object:
Json.stringify (xiaoming, [' Name ', ' skills '], ');
Output results
{ "name": "Xiaoming", "Skills": [ "JavaScript", "Java", "Python", "Lisp" ]}
You can also pass in a function that uses a function to handle the pre-processing key-value pairs:
function CONVERT (key, value) { if (typeof value = = = ' String ') { return value.touppercase (); } return " ); /* {The value is all capitalized. } Name ": Xiaoming", "age": +, "gender": true, "height": 1.65, "grade": null, "Middle-school": "\" W3c\ "Middle SCHOOL", "skills": [ "JAVASCRIPT", "JAVA", "PYTHON", "LISP" ]} */
Convert a JSON string to a JS object
The JSON string can be converted to a JS object directly with Json.parse. As shown in the following code:
// [1, 2, 3, True] // Object {name: ' Xiaoming ', age:14} // true // 123.45
Parse can also accept a function to perform the corresponding operation on key and value at parse Time:
Json.parse (' {' "name": "Xiaoming", "Age": +} ', function (key, value) { //Put number * 2: if (key = = = ' Name ') {
return value + ' classmate '
; } return value;}); Object {name: ' Xiao Ming classmate ', age:14}
JavaScript Learning notes and knowledge point finishing _3