jquery - 按类名查找下一部分
问题描述
如何form_section
通过单击显示下一个带有类的 div .btn_next
?
$(".form_section").hide();
$(document).on("click", ".btn_next", function(e) {
$(this).next(".form_section").show();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row form_section">
<div>
<div></div>
<div></div>
<button class="btn btn-primary btn_next">SHOW NEXT SECTION</button>
</div>
</div>
<div class="row form_section">
<div>
<div></div>
<div></div>
<button class="btn btn-primary btn_next">SHOW NEXT SECTION</button>
</div>
</div>
<div class="row form_section">
<div>
<div></div>
<div></div>
<button class="btn btn-primary btn_next">SHOW NEXT SECTION</button>
</div>
</div>
解决方案
首先你需要隐藏当前的“ .form_section
”部分(到被点击的按钮),然后得到下一个.form_section
显示。
<script>
//$(".form_section").hide();
$(document).on("click", ".btn_next", function(e){
$(this).parents('.form_section').hide();
$(this).parents('.form_section').next().show();
});
</script>
推荐阅读
- image - 如何在 Flutter 中显示字节数据中的图像
- powershell - 在PowerShell中映射驱动器的脚本
- angular - 使用数据初始化 Angular 反应式表单 - 表单数据不显示
- python - 使用合成数据创建一个简单的 csv - Python
- r - 是否有基于名称向量添加多列的稳定(非弃用)dplyr 方式?
- python-3.x - 为什么我的 setup.py 没有正确更新 python 路径?
- javascript - Fusebox 无法识别 sourceRoot 的属性设置
- python - Change nested json estructure from python dict
- python - 为层次聚类算法设置初始聚类结构
- java - 硒的假阳性和假阴性令人困惑