Let's look at an example first.
| The code is as follows |
Copy Code |
<style> #name { Display:none; } </style> <body> <div id= "Name" > The My name is smile. </div> </body> <script> Window.onload=function () { document.getElementById (' name '). style.display= ""; Alert ("Test"); } </script> |
The CSS defines the ID?? Ame Div for hidden, and we in the page after the completion of the load with JS control of the ID displayed, this write wrong?
Wood wrong? But why is the interface still blank?
Do you remember? Another use is xxx.style.display= "block" then let's try it,
Alas, it shows!!!.
Let's look at the difference between style.display= "" and style.display= "block" usage.
In fact, the biggest difference between the two is that block is displayed, so it will be wrapped, so since it is so different, why in this example one can show that one does not? troubled.
Okay, let's get this over with, let's see how we can solve this problem first, besides using style.display= "block", there is another way:
| The code is as follows |
Copy Code |
<div id= "name" style= "Display:none" > The My name is smile. </div> <script> document.getElementById (' name '). style.display= ""; </script> |
It is to put the style of ID name into the label, so that no matter the display= "" or display= "block" can be normal display!!!
Share your own doing, we do not put display= "", but directly set block or none so that there is no problem on the, try not to use empty or other characters oh.