In js, style. display = "" is invalid. jsstyle. display
This article describes how style. display = "" is invalid in js. Share it with you for your reference. The solution is as follows:
I. Problem description:
In js, we sometimes want to dynamically control the display or hide of a div or more operations, but if we style. display = "" May cause no effect.
See the following code:
Copy codeThe Code is as follows: <style>
# Name
{
Display: none;
}
</Style>
</Head>
<Body>
<Div id = "name">
My name is smile.
</Div>
</Body>
</Html>
<Script>
Window. onload = function (){
Document. getElementById ('name'). style. display = "";
Alert ("test ");
}
</Script>
Css defines the div whose id is name as hidden. After the page is loaded, we use js to control the id to display it. Is this wrong?
What's wrong with wood? But why is the interface still blank?
Ii. solution:
I remember another usage: xxx. style. display = "block". Let's try it,
Whining, it turned out to be displayed !!!
Let's take a look at the differences between style. display = "" And style. display = "block.
In fact, the biggest difference between the two is that the block is displayed in blocks, so the line breaks. So what is the difference? Why can one be displayed in this example? Confusions.
Okay, let's let it go first. Let's take a look at how we can solve this problem first. In addition to using style. display = "block" to solve it, there is another way:
Copy codeThe Code is as follows: <div id = "name" style = "display: none">
My name is smile.
</Div>
<Script>
Document. getElementById ('name'). style. display = "";
</Script>
The style with id as name is built into the label like style, so that it can be displayed normally regardless of display = "" or display = "block!
I hope this article will help you with javascript-based web programming.
Why is the li2styledisplay = 'block' of JavaScript Invalid? A: The code is not enough. I will package it for you. This is a navigation bar js.
Li2.style. display = 'block'; does not specify the li?
Because I don't know what effect to achieve, I can't try it.
Li2 [I]. style. display = 'block ';
CSS defines the display: none. How does js display it, not only Block
If you use a style file or <style> css </style> to set the display: none style of an element, use js to set the style. display = "" Cannot display elements. It can be replaced by block or inline values. This issue does not occur when you set the element directly through style = "display: none ".