code show as below:
<p class="box">
<ul>
<li><a href="#">我是链接1</a></li>
<li><a href="#">我是链接2</a></li>
<li><a href="#">我是链接3</a></li>
<li><a href="#">我是链接4</a></li>
<li><a href="#">我是链接5</a></li>
<li><a href="#">我是链接6</a></li>
<li><a href="#">我是链接7</a></li>
<li><a href="#">我是链接8</a></li>
<li><a href="#">我是链接9</a></li>
<li><a href="#">我是链接10</a></li>
</ul>
</p>
The above is the HTML structure. How to use JAVASCRIPT (not JQUERY) to only display 5 links and hide the rest. You need to click on the picture or text to display it, and then click to hide it. How can I achieve this function?
Currently displayed:
I am link 1
I am link 2
I am link 3
I am link 4
I am link 5
...
I am link 10
The effect you want to display:
I am link 1
I am link 2
I am link 3
I am link 4
I am link 5
︿ //Click here to expand the remaining "I am link" 6-10", then click to hide "I am the link 6-10".
Let’s talk about a stupid way, asynchronous request. Load only what you need first, click the button to request the rest, and dynamically load it into the page. Add a class to the newly added li for click hiding.
The code is rather ugly, please forgive me (using jquery api)
After reading the above answers, I don’t think they are my thoughts. Let’s talk about mine here
Every time you call loadNode(), pass in the number of li to be generated as a parameter, and it can be generated dynamically
I can’t quite understand what you mean
css:
Set a reserved classname for li, such as .hide {display:none}
Now add hide to the following li classes
js:
Use the click event to trigger to determine whether there is a hide, and then delete the class or add the class according to the situation.
Probably this is the route.
<button onclick="toggle_fn()">toggle button</button>
<script>
</script>
The idea is to let ul overflow:hidden and then change the height.
Wrote a draft https://jsfiddle.net/straybug...