2010-03-29 53 views
4

他, 我有這個頁面,我有一個表中的每個項目旁邊的複選框,並希望允許用戶選擇其中的一些,然後按我的刪除按鈕。我只是不能想出了jQuery爲了使確認窗口,只有「是」推提交 - 這是我的網頁ASP.NET MVC - 如何讓用戶確認刪除

<%Html.BeginForm(); %> 
<%List<ShopLandCore.Model.SLGroup> groups = (List<ShopLandCore.Model.SLGroup>)Model; %> 
<%Html.RenderPartial("AdminWorkHeader"); %> 
<table width="100%" id="ListTable" cellpadding="0" cellspacing="0"> 
    <tr> 
     <td colspan="5" class="heading"> 
      <input type="submit" name="closeall" value="Close selected" /> 
      <input type="submit" name="deleteall" value="Delete selected" /> 
     </td> 
    </tr> 
    <tr> 
     <th width="20px"> 
     </th> 
     <th> 
      Name 
     </th> 
     <th> 
      Description 
     </th> 
     <th width="150px"> 
      Created 
     </th> 
     <th width="150px"> 
      Closed 
     </th> 
    </tr> 
    <%foreach (ShopLandCore.Model.SLGroup g in groups) 
     { %> 
    <tr> 
     <td> 
      <%=Html.CheckBox(g.Id.ToString()) %> 
     </td> 
     <td> 
      <%=g.Name %> 
     </td> 
     <td> 
      <%=g.Description %> 
     </td> 
     <td> 
      <%=g.Created %> 
     </td> 
     <td> 
      <%=g.Closed %> 
     </td> 
    </tr> 
    <%} %> 
</table> 
<%Html.EndForm(); %> 

請注意,它只能進行刪除它應該確認,而不一定是關閉按鈕。

回答

6

只需將以下內容添加到您的頁面頂部:

<script type="text/javascript"> 
    $(document).ready(function(){ 
     $("input[name='deleteall']").click(function() { 
      return confirm('Delete all selected elements?'); 
     }); 
    }); 
</script> 
5

您應該在您的按鈕上放置一個javascript onclick方法,以顯示一個消息框,然後在用戶選擇否時停止處理點擊。

您可以通過修改刪除按鈕的代碼:

<input type="submit" name="deleteall" value="Delete selected" onclick="return confirm('Are you sure you want to Delete?');"/> 
4

下面是如何註冊點擊事件的按鈕悄悄地使用jQuery(不含混合HTML標記和腳本邏輯):

$(function() { 
    $('input[name=deleteall]').click(function() { 
     return confirm('Are you sure'); 
    }); 
});