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