简体   繁体   English

隐藏div并启用按钮单击

[英]Hiding divs and enable on button click

I have multiple rows 我有多行

<div class="row" id="move-data-row0"></div>
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>

I want only the first three to be shown and on a button click 3 more should appear. 我只想显示前三个,按一下按钮就会出现另外三个。

My first thoughts were to give every div the same classname with an index but I do not know how the JavaScript should be implemented. 我的第一个想法是给每个div与索引相同的类名,但我不知道应该如何实现JavaScript。

I started by trying to hide one div, but that doesn't really work 我开始尝试隐藏一个div,但这并没有真正起作用

$("#move-data-row0").children().prop('disabled',true);

You can use this minimal example, or improve it to get what you really want: 您可以使用此最小示例,或者对其进行改进以获得您真正想要的内容:

HTML: HTML:

<div class="row">1</div>
<div class="row">2</div>
<div class="row">3</div>
<div class="row">4</div>
<div class="row">5</div>
<div class="row">6</div>
<div class="row">7</div>
<button>More</button>

JavaScript: JavaScript的:

$(document).ready(function(){
    $('.row:gt(2)').hide();
    $('button').click(function(){
        $('.row:hidden:lt(3)').show();
    });
});

FIDDLE: https://jsfiddle.net/lmgonzalves/e0ppjwnm/ FIDDLE: https ://jsfiddle.net/lmgonzalves/e0ppjwnm/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM