We use a button to call this function: Point the button's Click event to this method
<input type= "button" value= "click Me" onclick= "Hanshu ()" >
Now I'm going to write another method in this way
In this method we point the body's click event to a new method, the anonymous method. Then pop the click Body
function AddClick ()
{
This does not achieve the body of the Click event to refer to the new method, because the bodies can not access functions in the function
/*
Document.body.onclick = new Function ()
{
Alert (' click Body ');
};
*/
This will achieve
Document.body.onclick = Btnan;
If you point the method to a method within a function, an error occurs: Neihanshu undefined
Document.body.onclick = Neihanshu;
}
function Btnan ()
{
Alert (' click Body ');
function Neihanshu ()
// {
Alert (the function in ' function is called ');
// }
Neihanshu ();
}
Brief introduction
function Hanshu ()
{
function Body ...
}
So we've defined a function called Hanshu, and now we're trying to call this function. In fact, it's simple to call a function by using the name of the function with parentheses, that is:
Hanshu ();
So we call this function.
We use a button to call this function: Point the button's Click event to this method
<input type= "button" value= "click Me" onclick= "Hanshu ()" >
Now I'm going to write another method in this way
In this method we point the body's click event to a new method, the anonymous method. Then pop the click Body
function Hanshu ()
{
Document.body.onclick = function ()
{
Alert (' click Body ');
};
}