2012-09-04 29 views
0

我想使用Jquery對話框在一個頁面上顯示註釋,該頁面有多個從數據庫調用的行 - 每行都有一個鏈接,顯示一個應顯示相關內容的對話框爲那一行。在循環中將值傳遞給Jquery對話框

對話框工作正常,但我不能讓它從鏈接中獲取一個值,因此我可以在對話框顯示的div中查詢數據庫。

當有人點擊圖片時,我希望它顯示該行的註釋 - 這是我目前使用的代碼。我知道我沒有發送一個值,因爲我不知道該怎麼做 - 我怎樣才能得到這個將行ID附加到每行圖像上,然後在對話框打開時使它在對話框中可用,以便顯示該註釋?

<script> 
$(function() { 
     $("#jui-dialog").dialog({ 
    autoOpen: false, 
    title: "Note", 
    modal: true, 
    width: "640", 
    buttons: [{ 
      text: "Close note", 
      click: function() { 
       $(this).dialog("close"); 
      }}] 
}); 
    $("#jui-dialog-mdl-btn").bind("click", function(event) { 
    $("#jui-dialog").dialog("option", {modal: true}).dialog("open"); 
    event.preventDefault(); 
}); 
}); 
</script> 

<while begins> 
<img src="/icons/16/note.png" title="View employee note" alt="View employee note" id="jui-dialog-mdl-btn"> 
<input type="hidden" value="<?=$id?>"> 
<while ends> 



         <div id="jui-dialog"> 
          <div class="dialog-inner"> 
           <?php         
           $query=mysql_query("SELECT content from notes WHERE id='$id'"); 
           $count=mysql_num_rows($query); 
           $row=mysql_fetch_array($query); 
           $note=$row['content']; 
           print $note; 
           ?> 
          </div> 
         </div> 

回答

1

首先:不要在while循環中使用id,因爲您不能在同一頁上使用兩個相同的id。你可以使用課程。 您可以使用您的驗證碼,:

<img src="/icons/16/note.png" title="View employee note" alt="View employee note" class="jui-dialog-mdl-btn"> 
<input type="hidden" value="<?=$id?>"> 

要得到員工的ID:

$('.jui-dialog-mdl-btn').click(function() { 
     var id = $(this).next('input').val(); 
     //process whatever you like 
}); 

要收到的數據,你想顯示,你可以使用一個隱藏的div像這樣:

<img src="/icons/16/note.png" title="View employee note" alt="View employee note" class="jui-dialog-mdl-btn"> 
<input type="hidden" value="<?=$id?>"> 
<div class="dialoginfo" style="display:none;"><!--code to show in your dialog--></div> 

然後在jQuery的:

$('.jui-dialog-mdl-btn').click(function() { 
    var id = $(this).next('input').val(); 
    $(this).next('.dialoginfo').dialog(/*options*/); 
    //process whatever you like 
}); 

當然您的實施可能會有所不同,但我希望您在這裏有詳細的摘錄