First, define the function:
View sourceprint? Function Hanshu ()
{
// Function body...
}
In this way, we define a function named Hanshu. Now we try to call this function. In fact, it is very simple. To call a function, use the name of the function to add brackets, that is:
Hanshu ();
In this way, we call this function.
Call this function with a button: point the button clicking event to this method.
<Input type = "button" value = "click me" onclick = "Hanshu ()">
Now I will write another method in this method.
In this method, we direct the Click Event of the body to a new method named anonymous. Click body
View sourceprint? Function Hanshu ()
{
Document. body. onclick = function ()
{
Alert (click body );
};
}
Now let's try to call
<Input type = "button" value = "click me" onclick = "Hanshu ()">
However, the click body dialog box appears when you click the body.
Because this method cannot be found when the body accesses this anonymous method
We can test it like this.
View sourceprint? Function AddClick ()
{
// In this way, the Click Event of the body cannot be assigned to a new method, because the body cannot access the function in the function body.
/*
Document. body. onclick = new function ()
{
Alert (click body );
};
*/
// This can be achieved
Document. body. onclick = BtnAn;
// If you direct the method to the method in the function, the following error occurs: NeiHanshu is not defined.
// Document. body. onclick = NeiHanshu;
}
Function BtnAn ()
{
Alert (click body );
// Function NeiHanshu ()
//{
// Alert (the function in the function is called );
//}
// NeiHanshu ();
}
So the result is: we can only call external functions, but cannot call functions in the functions. This is an access level problem.