[英]jQuery toggle on PHP foreach loop
Using codeigniter 3.x 使用Codeigniter 3.x
i'm trying to get data from database using foreach loop. 我正在尝试使用foreach循环从数据库获取数据。
<h3 style="margin-right:15px;" id='hideshow'>August 2016</h3>
<?php foreach($duxeos as $e): ?>
<div class='content' ><h4 class="dropdate"><?php echo $e->fulldate;?></h4><div class="cdropdate" class="defhide"><?php echo $e->content;?></div></div>
<?php endforeach; ?>
javascript : javascript:
jQuery(document).ready(function(){
jQuery('.hideshow').live('click', function(event) {
jQuery('.content').toggle('show');
});
});
jQuery(document).ready(function(){
jQuery('.dropdate').live('click', function(event) {
jQuery('.cdropdate').toggle('show');
});
});
now it's working, but when i press the hide button, it hide all content, how can i hide content that i want ? 现在它可以工作了,但是当我按下“隐藏”按钮时,它隐藏了所有内容,我该如何隐藏我想要的内容?
this
context in handler-function
handler-function
使用this
上下文 .on
instead of .live
.on
而不是.live
.closest
to get the closest element in order to find child of it. .closest
获取最接近的元素,以便找到它的子元素。 jQuery(document).ready(function() { jQuery('.dropdate').on('click', function(event) { jQuery(this).closest('.content').find('.cdropdate').toggle(); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <h3 style="margin-right:15px;" id='hideshow'>August 2016</h3> <div class='content'> <h4 class="dropdate">Full-Date</h4> <div class="cdropdate defhide">Content</div> </div> <hr> <div class='content'> <h4 class="dropdate">Full-Date</h4> <div class="cdropdate defhide">Content</div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.