2011-07-30 5 views
0

안녕하세요, PHP는 mysql 데이터베이스 페이지 매김 페이지를 구축하고있어, 그래서 레코드의 목록에서 2 행이 긴 내가 위의 스팬을 클릭하면 열리는 div가 원하는 방법 내가 jQuery를 설정하지가 <p>의 ID를 취하고 JQuery와 그것을 확장되도록 그것을 만들jquery 함수 passsing 변수

<span id="button1">Toggle</span> 

<p id="p1"> 
hello<br/>hello 
</p> 

<script> 
$("#button1").click(function() { 
$("#p1").slideToggle("slow"); 
}); 
</script> 

난 PHP에 MySQL에 출력 버튼 모두 다른 ID가되고, P가있을 때 다른 id도 마찬가지입니다.

+0

PHP 코드의 id 필드에 "button1"을 출력 했으므로 PHP 코드의 jQuery 코드에 "button1"을 출력 할 수도 있습니다. 다시 말해 두 이름 모두에서 이름을 설정할 수 있기 때문에 동적 인 이름은 중요하지 않습니다. –

+0

클래스 이름을''p'로 지정하는 것은 어떻습니까? 이런 식으로 모두 한꺼번에 선택할 수 있습니다. – Ibu

답변

0
//Jquery Code which calls toggle_visibility function 
    $(".pOne").click(function(){ 
       toggle_visibility('partsIdThree'); 
      }) 
      .toggle(function() { 
       $(this).children("span").text("[-]"); 
      }, function() { 
       $(this).children("span").text("[+]"); 
      }); 

    //HTML Code 
<div id="parts_toogle_one">  
<p class="pOne">Add Records <span>[+]</span></p> 
     <div id="msg_body_one"> 
     <tr><td></td></tr> 
     </div> 
</div>  

    // Javascript code 
function toggle_visibility(id) { 
    var e = document.getElementById(id); 
    if(e.style.display == "inline") { 
     e.style.display = 'none'; 
    } 
    else if(e.style.display == "none") { 
     e.style.display = "inline"; 
    } 
}    

이와 비슷한 것입니다.

0

당신은 결과의 수에 대해 걱정할 필요가 없습니다 그래서 당신은, 동적 ID를 검색하는 사용할 수 있습니다 .. 예를 들어

:

<?php $i = 0;?> 
<?php foreach($resultset as $result) : ;?> 

<span class="activator" id="result<?php echo $i;?>">CLICK HERE</span> 
<div id="panel_result<?php echo $i;?>">SLIDER DIV</div> 

<!-- Do the rest of you processing of $result here; it just doesn't matter, for here you only need some identification, I used a number for convenience. --> 

<?php ++$i;?> 
<?php endforeach;?> 

귀하의 JQuery와 :

$('.activator').click(function(){ 
var the_id = $(this).attr('id'); 
var the_panel = $('#panel_' + the_id); 
$(the_panel).slideToggle('slow'); 
}); 

PHP로 인쇄하는 각 줄에 대해 jQuery 명령을 작성할 필요가 없으므로이 스 니펫을 사용하면 스팬을 클릭하면 어떤 슬라이드를 사용할 것인지 자체적으로 결정됩니다.

+0

와우, 정말 고마워요. 데미안, 지금이 말이 맞아요. – Andie

+0

이것은 너무 아름답게 쓰여졌습니다. – Andie