2011-06-13 88 views
0

我是新來的jQuery和傳遞變量到一個jQuery UI的對話框有困難。點擊「是」時,瀏覽器應重定向到localAuthorityDelete並刪除相應的記錄。傳遞變量到jQuery UI的對話框

<script type="text/javascript"> 
    $(document).ready(function(){ 
     $('#deleteButton').click(function(){ 
      $('#deleteText').dialog({ 
      modal:true, 
      resizable: false, 
      buttons: { 
       'Yes': function() { 
        window.location = "../php/localAuthorityDelete.php?laID=" 
        $(this).dialog('close'); 
       }, 
       Cancel: function() { 
        $(this).dialog('close'); 
       } 
      },         
      }); 
     }); 
    }); 
</script> 

我有很多的刪除按鈕:

<input type="button" id="deleteButton" name="deleteButton" value="Delete"> 

每個刪除按鈕是在旁邊的桌子應刪除的記錄。我是這樣做的:

<a href="localAuthorityDelete.php?laID=<?php echo $row_laID['laID'];?>">Delete</a> 

但需要利用jQuerys對話框。如果有人能幫助我,我會非常感激。我曾嘗試在一個函數中包裝上述JS,該函數只接受一個變量,但它不運行。

感謝您的幫助。

邁克

+3

請勿使用GET來更改Web應用中的狀態。如果該頁面沒有受到保護並且被蜘蛛抓取,則會有很多被刪除的記錄。 – 2011-06-13 13:40:27

回答

1

看起來你有多個deleteButtons,但是,對於一個HTML元素的ID應該是唯一的。 因此改變你呈現刪除按鈕如下的方式:

<input type="button" 
     id="delete-<?php echo $row_laID['laID'];?>" 
     class="deleteButton" 
     name="deleteButton" 
     value="Delete" 
/> 

現在你可以得到元素的ID從刪除按鈕的ID被刪除。 而現在點擊處理程序應該被綁定到.deleteButton而不是#deleteButton。

<script type="text/javascript"> 
    $(document).ready(function(){ 
     $('.deleteButton').click(function(){ 
      var id = this.id.replace(/[^0-9]/g, ""); 
      $('#deleteText').dialog({ 
       modal:true, 
       resizable: false, 
       buttons: { 
        'Yes': function() { 
         window.location = "../php/localAuthorityDelete.php?laID=" + id; 
         $(this).dialog('close'); 
        }, 
        Cancel: function() { 
         $(this).dialog('close'); 
        } 
       } 
      }); 
     }); 
    }); 
</script> 
+1

感謝您的時間。這很好。 – user795954 2011-06-14 10:03:05