我有一个脚本,当我单击一个div时,将显示或隐藏另一个div。
效果很好,但是当我在sql查询中使用它并单击一个div时,所有其他div都将显示:)所以我在考虑一个增量脚本,以便它将自动为div自动编号(效果很好)但是我不知道在Java脚本中使用什么,以便它能正常工作。
这是代码:
<?php
$conn = mysql_connect("localhost","user","pass");
mysql_select_db("database");
mysql_set_charset("UTF8", $conn);
$a = 1;
$b = 1;?>
<script>
$(".Denumire<?php echo $a; ?>").click(function(){
$(".Informatie<?php echo $b; ?>").toggle();
})
</script><?php
$construct ="SELECT * FROM tablename ";
$run = mysql_query($construct) or die(mysql_error());
$foundnum = mysql_num_rows($run);
// Define $color=1
$color="1";
if ($foundnum==0)
{
echo "Nu avem Informații!";
}
else
{
while($runrows = mysql_fetch_assoc($run))
{
$Denumire = $runrows ['Denumire'];
$Informatie = $runrows ['Informatie'];
echo "
<div id='dam'>
<div class='Denumire".$a++."'>
<table>
<tr>
<td>$Denumire</td>
<td><img src='http://bios-diagnostic.ro/wordpress/img/gobottom.png'></td>
</tr>
</table>
</div>
<div class='Informatie".$b++."'><br>$Informatie<br></div>
</div><hr><br><br>
";}}?>
问题出在Java脚本中...一些想法将不胜感激...谢谢大家。
jQuery中有一个兄弟姐妹方法,我相信它的效果很好,因此javascript应该是
<script>
$(".Denumire").click(function(){
$(this).siblings(".Informatie").toggle();
})
</script>
和显示部分
<div class='Denumire".$a++."'>
应该
<div class='Denumire'>
希望这项工作:D
[编辑]
关闭其他人:
<script>
$(".Denumire").click(function(){
$(".Informatie").hide();
$(this).siblings(".Informatie").show();
})
</script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句