[英]Modify Script to Close Div
我有一个很好的小展示,它一次只显示一个div,我在以下位置找到它: 随机代码片段 (第二个演示向下),如下所示:
function showonlyone(thechosenone) {
$('.newboxes').each(function(index) {
if ($(this).attr("id") == thechosenone) {
$(this).show(200);
}
else {
$(this).hide(600);
}
});
}
它唯一不执行的操作是在打开div之后将其关闭。 目前,我将两个div都设置为显示:none,并希望为用户提供在完成查找后将它们都关闭的选项。
任何想法如何修改此?
您可以单击事件将其单击时将其关闭:
$('.newboxes').click( function() {
$(this).hide(600);
});
您必须向用户提供按钮或其他东西以关闭div。 假设每个div中都有一个这样的按钮:
的HTML
<div class="div-class">
<p>Box content</p>
<button class="close">Close</button>
</div>
jQuery的
$('.close').on('click', function() {
$(this).closest('.div-class').hide();
});
在if
语句中添加有关当前项目可见性的条件:
function showonlyone(thechosenone) {
$('.newboxes').each(function(index) {
if ($(this).attr("id") == thechosenone && $(this).css("display") == "none") {
$(this).show(200);
}
else {
$(this).hide(600);
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.