2013-08-27 32 views
0

大家好,我想要一個在點擊一個按鈕時可以切換php的while循環的div。特定的div應該在特定的按鈕被點擊時切換。 到目前爲止,我已經嘗試過,它的工作原理,但只適用於循環的第一個div。只有第一個div被切換,請幫助。在ajax中切換一個位於php循環中的div

顯示註釋要點擊的按鈕:

<td colspan=2 style="background-color:#FFFBE6;opacity:.89;height:25px;max-height:27px;"> 
        <div style="float:left;margin-left:80px;" id="ratinginadiv"> 
        <b class="ratings" id="showcomm" onclick="showcomments(this);"><?=$no_ofcomments?> comments |</b> <b class="ratings"><?=$no_offollowers?> Following </b> | 
        <b onclick="displaystars();" class="ratings">Star</b>|</div></td> 


div id="commentdiv"> 
      <table style="background-color:#DDFFFF; border:1px solid #C9D291;width:100%;margin-bottom:0px;border-top:0px;margin-top:0px;" align="center" cellspacing=0> 
        <?php 
        $onid=$postainarray['id']; 
        $selectcomments=mysql_query("select comments,time,onemail,emailid ,hidden from waf where onid_comment='$onid' and comments!='' "); 
        while($commentsinaray=mysql_fetch_array($selectcomments)){ 
        $commemail=$commentsinaray['emailid']; 
        $dataofcommenter=mysql_query("select name,pic,email,dob,gender from fk_mem where email='$commemail'"); 
        $datainarray=mysql_fetch_array($dataofcommenter); 
        if($commentsinaray['hidden'] == 'hide'){ 
        $nameintitle='hidden'; 
        $emailintitle='hidden'; 
        $picofcomm="blur.jpg"; 
        } 

        else{ 
        $nameintitle=$datainarray['name']; 
        $emailintitle=$datainarray['email']; 
        $picofcomm=$datainarray['pic']; 
        } 
        ?> 
      <tr> 
       <td align="center" style="width:55px;background-color:white;opacity:1;border-bottom:2px solid white;"> 
        <a title="<?=$nameintitle?>,<?=$datainarray['gender']?>,[<?=$datainarray['dob']?>],<?=$emailintitle?>" href="profile_page_name.php?friendemail=<?=$emailintitle?>"><img src="uploads/<?=$picofcomm?>" style="width:40px;max-height:55px; border:1px solid green;padding:1px;" /></a> 
       </td> 
       <td align="left" style="background-color:#F3FCFF;opacity:1;border-bottom:2px solid white;"> 
        <a href="profile_page_name.php?friendemail=<?=$emailintitle?>" title="Go to <?=$nameintitle?>'s Profile.." style="text-decoration:none;color:#718E99;font-weight:normal;margin-left:5px;margin-bottom:0px;"> 
        <?=$nameintitle?></a><br> 
        <p style="margin-left:5px;margin-top:0px;"><?=$commentsinaray['comments']?></p> 
       </td> 
       <td align="left" style="width:65px;vertical-align:top;border-left:2px solid white;border-bottom:2px solid white;"> 
        <small style="color:red;font-size:14px;"><?=$commentsinaray['time']?></small> 
       </td> 
      </tr> 
      <?php } ?> 
      <tr> 
      </table> 
      </div> 


function showcomments(obj){ 
    var currentdiv = $("#commentdiv"); 
     currentdiv.slideToggle(); 
    } 

回答

0

人哦男人...持有malform表格式不正確的表內的div ...

的代碼的toogle無處不在,我假設你唯一的問題是因爲你沒有爲每個div分配唯一的ID。在您的循環中添加一個計數器,然後將其添加到div ID「commentDiv」

在添加功能之前正確獲取頁面結構。