<!DOCTYPE HTML><HTML><Head><MetaCharSet= "UTF-8"><title>Custom Objects</title> <!--A custom object is a special type of data that is encapsulated by properties and methods. - <Scripttype= "Text/javascript"> functionmethod1 () {var Person=NewObject (); //Add PropertyPerson.name="Rez Apart"; Person.spell=957; //Add Method 1.Person.say=NewFunction ("alert (' Person.name ')"); //Add Method 2.Person.way=The ; function() {varNum=0; for(varI=0; I< -; I++) {num+=i; } alert (num); } } /*Constructors Create Objects*/ functionPerson (name,age) {//Defining Properties This. Name=name; This. Age=Age ; //To define a member method: This. Sayname=function() {alert ( This. Name); } } functionmethod2 () {varP=NewPerson (); //creating objects from the constructor } /*JSON is a lightweight data Interchange format:-use key-value pairs as definitions-names need to be enclosed in double quotes ""-Multiple pairs of definitions used, separated by */ functionmethod3 () {varP={"name":"Angela Chang Han"," Age": -,"say":function() {alert ("The farthest place to see")}}; }</Script></Head><Body> <inputtype= "button"onclick= "method1 ();"value= "Create a generic object template!"> <inputtype= "button"onclick= "method2 ();"value= "Create object template!"> <inputtype= "button"onclick= "method3 ();"value= "Create JSON object template!"></Body></HTML>
2. Cancel the event:
<!DOCTYPE HTML>
<Head><MetaCharSet= "UTF-8"><title>Cancel Event notation</title> <Scripttype= "Text/javascript"> functionjudge () {varresult=Confirm ('Are you sure you want to delete it? '); returnresult; }</Script><Body> <form> <inputtype= "text"value= "I am the data to be submitted"> <inputtype= "Submit"value= "Delete"onclick= "Judge ();"> </form> </Body></Head>
3. Event compatibility
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "UTF-8"><title>Cancel Event notation</title> <Scripttype= "Text/javascript"> functionFun (e) {console.log (event.clientx+ ', ' +event.clienty);//Gets the position of the click, in pixels, the sub-notation may appear incompatible issues
//Incompatible Hint: Reffereceerror event is not defined
The compatible wording is as follows:
Console.log (e.clientx+ ', ' +e.clienty);
/* Gets the writing of the event source (that is, the target node of the event)
IE:event.srcElement
Fire Fox:event.target
*/
Console.log (event.srcelement);
Console.log (Event.target);
Compatible wording:
var evesrc=event.srcelement| | Event.target;
Console.log (Evesrc.nodename);
}
</ Script >
< Body > <p onclick= "Console.log (EVENT.CLIENTX); >
HTML usage
</p>
<p onclick= "Fun (event);" >
JS use
</p>
</ Body > </ Head > </ HTML >
JavaScript custom object/Cancel Event/Event compatibility/Cancel bubbling