2015-01-09 3 views
0

현재 div를 클릭하면 다른 페이지로 데이터가 게시되고 div가 다시로드됩니다. 새 div에 이전 버튼을 다시 가져 오기 위해 뒤로 버튼 (#backref)을 추가하고 싶습니다. 이것에 대한 몇 가지 게시물을 발견하여 div에 display:none;을 추가했지만 찾아보기를 원하지만이 CSS를 사용할 수 없기 때문에 이것은 분명히 초기 div입니다. 이 라운드를 얻는 방법에 대한 제안은 감사하겠습니다!jQuery를 사용하여 div 간 이동

$(document).ready(function() { 
$('.clickthrough2').click(function() { 
    // get car id 
    carId = $(this).attr('id'); // get the car id to access each class element under the car div container 

    $.post('referrer-ajax2.php', { 
     clickthrough: $('#car-'+carId+' .clickthrough').val(), 
     ref_date_from2: $('#car-'+carId+' .ref_date_from2').val(), 
     ref_date_to2: $('#car-'+carId+' .ref_date_to2').val() 
    }, 
    function (data) { 
     $('#car1').html(data); 
    }); 
});  
}); 

의 index.php : 내가 이것을 달성하기 위해 사용하고

코드

<div id="car1" class="declined3 statdivhalf2"> 
<h4>Select Car</h4> 

<div class="statgrid"> 
    <?php 
    $result=$ mysqli->query($sql); 
    if($result->num_rows === 0) { echo 'No Cars in selected time period.'; } 
    else { while ($row = $result->fetch_array()) { 
    ?> 
<div id="car-<?php echo $row['car_id'];?>"> 
<input type="hidden" class="ref_date_from2" value="<?php echo $date_from; ?>" /> 
<input type="hidden" class="ref_date_to2" value="<?php echo $date_to; ?>" /> 
<input type="hidden" class="clickthrough" value="<?php echo $row['car_name'] ?>" /> 
<a><div id="<?php echo $row['car_id'];?>" class="clickthrough2 col-5-6"><?php echo $row['car_name'] ?></div></a> 
</div> 

    <div class="col-1-6"> 
     <?php echo $row[ 'quantity']; ?> 
    </div> 
    <?php } } ?> 
</div> 
</div> 

참조 자-ajax2.php는 :

<div id="car1" class="declined4 statdivhalf2"> 
    <h4>Car Details</h4> 

<div class="statgrid"> 
    <?php 
    $result=$ mysqli->query($sql); 
    if($result->num_rows === 0) { echo 'No Cars in selected time period.'; } 
    else { while ($row = $result->fetch_array()) { 
    ?> 
    <div id="clickthrough2" class="col-5-6"><?php echo $row['car_details'] ?></div> 
    <div class="col-1-6"><?php echo $row[ 'quantity']; ?></div> 
    <?php } } ?> 
    <a><div id="backref">< Back</div></a> 
</div> 
</div> 

편집 : 나는 아래 시도 작동하지 않았습니까?

$('#backref').click(function() { 
    $('.declined4').hide(); 
    $('.declined3').show(); 
}); 

답변

1

div를 새 콘텐츠로 다시로드하는 대신 이전 div를 숨길 때마다 div를 새로 만들 수 있습니다. 그런 다음 id 또는 (더 나은) "data-"속성을 사용하여 각 div를 인덱싱하여 순환시킵니다.

+0

예가 있으십니까? 전에는 그 방법에 대해 들어 보지 못했습니다. – n00bstacker

+0

여기에 jQuery : S를 사용하여 새 div를 만듭니다. 아니면 더 숨기고 숨기기를 의미합니까? – n00bstacker

+0

코드에서 수행중인 작업 function (data) { $ ('# car1') .html (data); }}); div를 숨기고 새 HTML로 새 div를 넣으려면 해당 행을 변경하십시오. –