Learning JS Native encountered a problem, solve the hope for everyone to help

Source: Internet
Author: User

Today, when I was studying native, I encountered a problem which is not a problem, how to call it a problem? Here's the question.

Window.onload=function ()

{
var Odiv=document.getelementbyid (' drop ');//Get to the whole box
var oh2=odiv.getelementsbytagname (' H2 ') [0];//get to playlist
var oul=odiv.getelementsbytagname (' ul ') [0];//get to playlist track
Oh2.onclick=showhideul; Give playlist a single chicken event call Showhideul
}

function Showhideul ()
{
if (OUl.style.display = = = ' None ')//show UL list if hidden or hide
{
oul.style.display= ' block ';
Oh2.classname= ' up ';
}
Else
{
Oul.style.display= ' None ';
Oh2.classname= ' down ';
}}

This is the original code, implementation is a playlist of the dropdown

Window.onload=function ()

{
var Odiv=document.getelementbyid (' drop ');//Get to the whole box
var oh2=odiv.getelementsbytagname (' H2 ') [0];//get to playlist
var oul=odiv.getelementsbytagname (' ul ') [0];//get to playlist track
Oh2.onclick=showhideul; Give playlist a single chicken event call Showhideul
function Showhideul ()
{
if (OUl.style.display = = = ' None ')//show UL list if hidden or hide
{
oul.style.display= ' block ';
Oh2.classname= ' up ';
}
Else
{
Oul.style.display= ' None ';
Oh2.classname= ' down ';
}
}}

This is my revised code, I put this showhideul method into the onload inside to reduce the amount of code, because there is no video explanation when looking at the code, so I do not know how to streamline the correct (but the program can do the normal execution)

()

So I read https://bbs.csdn.net/topics/390498828 's question and answer.

OnLoad method: When the page opens, it is necessary to wait until all elements of the page are loaded, and the self-executing function starts when JS loads, so when you write a self-executing function as a dead loop and introduce a head, the page doesn't show anything.

Because the page has been executing this dead loop does not parse down the meaning of the body onload is that the document has been loaded and the elements within the page can be used  

Learning JS Native encountered a problem, solve the hope for everyone to help

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.