Example Analysis of if statement
If sentence example analysis, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
All events contain three elements of the js event:
1, the event source (that is, the tag or element that triggers the event)
2, event name (name of response event)
3. Analyze the response of the event
In this case, it is obvious that the p tag is the event source that triggers the event, onclick is the event name, and the response triggered is not fixed.
That is, it will correspond to different events according to different conditions. So, of course, we need to add a condition, and the specific usage is:
If (condition) {
/ / do something
}
Code:
/ / html part
Input method
to write
Pinyin
Close
/ / js part
Var oul=document.getElementById ("uul")
Function ou () {
If (oul.style.display== "block") {
/ / pay special attention to the equal sign above to judge whether it is equal or not, and the equal sign below is an assignment
Oul.style.display= "none"
} else {
Oul.style.display= "block"
}
}
After reading the above, have you mastered the method of example analysis of if statements? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!