JS of the OnLoad incident point of Use experience _ basic knowledge

Source: Internet
Author: User
If I asked you what Window.load and window.onload meant, I'm afraid you would answer me, "This is not the end of the page."
But the answer is not necessarily, depends on how you use. Take a look at the example.
Example 1:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<title>Untitled</title>
<script type= "Text/javascript" >
function ShowMessage ()
{
Alert ("true");
}
Window.onload=showmessage ();
</script>
<body>
You can't see me when you see true
</body>

When you see the pop-up box true, you definitely do not see "When you see true, you do not see me", the page has not been loaded after the start of JS has been implemented.
Example 2
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<title>Untitled</title>
<script type= "Text/javascript" >
function ShowMessage ()
{
Alert ("true");
}
Window.onload=function () {showmessage ();}
</script>
<body>
You saw me when you saw true.
</body>

When you see the pop-up box of True, you will also see "You see me when you see true", this is the real page load to trigger.
PS: Recommend the use of anonymous functions such as the OnLoad event, i.e. window.onload=function () {showmessage ();} This form.

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.