JS function Simple Call examples

Source: Internet
Author: User
Tags anonymous

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 ');
};
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.