0

I have a script that when i click on one div, will make another div show or hide.

That works great, but when i use that in an sql query and i click on one div, all the other ones will show :) So i was thinking at an incremental script so that it will auto number the div automatically (which works great) but i don't know what to use inside java script so that it will work.

Here is the code:

<?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>
";}}?>

The problem is in the java script... Some ideas will be appreciated ... thank you all.

4

1 回答 1

2

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>
于 2013-07-30T14:35:59.500 回答