我有一个ID为'b1'的div for循环。这个div是可点击的,当我点击这个链接时,我想显示与该div相关的标签以显示在该特定的div b1下面。但是作为按我的代码,它只是显示第一div.Below标签是我的代码如何显示使用jQuery的for循环中的每个链接的标记?
<head>
<script type="text/javascript">
<script src="http://code.jquery.com/jquery-1.10.1.js"></script>
$(document).ready(function(){
$("#b1").click(function(){
$('#newdiv').slideToggle();
$id= $(this).attr('data-target');
$src = $('#newdiv');
$idTrg = $('#'+$id);
$src.html($idTrg.html());
});
});
</script>
<style>
#newdiv{
width:100px;
height:100px;
background-color:orange;
}
/*#newdiv:hover{
text-decoration:underline;
}*/
</style>
</head>
<body>
<?php for($i=1;$i<9; $i++): ?>
<div id="whole">
<div id="b1" data-target="<?php echo $i; ?>">Content<?php echo $i; ?></div>
<div id="newdiv" style="display:none" ></div>
</div>
<?php endfor; ?>
<?php for($j=1;$j<9; $j++): ?>
<div id="<?php echo $j ;?>" style="display:none">
Main contents<?php echo $j; ?>
<div id="another">Inside Another one<?php echo $j; ?></div>
</div>
<?php endfor; ?>
</body>
我怎样才能得到各格的内容出现在其下方上点击链接?可能有人帮助我与这个jQuery
的标签是 “整” 或 “newdiv”? – Sora
对于'newdiv'''newdiv'是'整个'内的div,它具有无显示的样式,并且仅在各自的'b1'div被点击时才显示 – Leah