2010-03-29 57 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'); 
    }); 
});