现在循环出3个酒店,现在每个酒店显示3条数据,每次点击其中一个酒店的展开所有信息后,3个酒店全部展开了,这个问题怎么解决,大侠帮忙
{{foreach name=name from=$hotel_rooms.HotelRoom item=room }} 
          {{if $smarty.foreach.name.iteration<4}}                                    
        <tr>
              <td width="122" class="blue"><p title="{{$room.room_name_full}}">{{$room.room_name}}</p></td>
              <td><ins class="f12b orange">{{$room.room_money_type}}{{$room.average_price}}</ins></td>
              <td align="right"><input name="" type="image" src="{{$http_file_url}}/image/common/yding.gif" /></td>
              
        </tr>
        {{else}}
        <tr style="display:none;" class="other_room">
              <td width="122" class="blue"><p title="{{$room.room_name_full}}">{{$room.room_name}}</p></td>
              <td><ins class="f12b orange">{{$room.room_money_type}}{{$room.average_price}}</ins></td>
              <td align="right"><input name="" type="image" src="{{$http_file_url}}/image/common/yding.gif" /></td>
              
        </tr>
        {{/if}}
          {{/foreach}}
              
          {{if $hotel_rooms.Count > 3 }}
        <tr>   
             <td colspan="3" id="open_other_rooms" ><span onclick="open_all_rooms();"  class="all_hourse hand" >展开所有数据(<span class="orange"> {{$hotel_rooms.Count}} </span>)</span></td>
             <td colspan="3" style="display:none;" id="close_other_rooms"><span  class="all_hourse hand" onclick="close_all_rooms();">收起(<span class="orange"> {{$hotel_rooms.Count}} </span>)</span></td>                              
        </tr>   
          {{/if}}     
<script type="text/javascript">
<!--  
  function open_all_rooms()
  { 
      $(".other_room").show();
      $("#open_other_rooms").hide();
      $("#close_other_rooms").show();
  
  }
  function close_all_rooms()
  {
      $(".other_room").hide();  
      $("#open_other_rooms").show();
      $("#close_other_rooms").hide();
  }

解决方案 »

  1.   

    大哥,smarty是不是模板啊?你在那里学的,那里有资料吗?
      

  2.   

    相同的类名了  class="other_room"
      

  3.   

    你需要为<tr style="display:none;" class="other_room">加注酒店的唯一标识,如:
    <tr style="display:none;" class="other_room" hotel="{{$room.hotel_id}}">
    其中的$room.hotel_id是我虚拟的,你可以根据你自己的数据结构来更改。和它对应的展开按钮也要作更改:
    <td colspan="3" id="open_other_rooms" hotel="{{$room.hotel_id}}"><span onclick="open_all_rooms({{$room.hotel_id}});"  class="all_hourse hand" >展开所有数据(<span class="orange"> {{$hotel_rooms.Count}} </span>)</span></td>最后更改一下js函数就可以了:
      function open_all_rooms(hotel_id)
      { 
          $(".other_room[hotel='" + hotel_id + "']").show();
          $("#open_other_rooms[hotel='" + hotel_id + "']").hide();
          $("#close_other_rooms[hotel='" + hotel_id + "']").show();
      
      }收起按钮如法炮制。
      

  4.   

    onclick里少了引号,应为:
    onclick="open_all_rooms('{{$room.hotel_id}}');"