jQuery 警报对话框 -- 确认和取消

jQuery Alert Dialog -- Confirm and Cancel

我希望添加一个警报,在选择 ID 为 deSelectAll 的按钮时弹出,带有确认选项,尽管在操作之后,或者取消并且 return 页面没有任何变化.目前我有以下代码。

$("#deSelectAll").click ->
    alert "Are you sure you want to remove all"
    root.table.$("tr").removeClass "selected"

但所有显示以下结果:

我也希望能够确认或取消请求。如何实施?

更新:我添加了确认按钮,但它根本不调用警报

# Deselecting all 
  $("#deSelectAll").click ->
    confirmRemovalFunct()

  confirmRemovalFunct = ->
    confirm("Are you sure you want to remove all locations from campaign")      

    #alert "Are you sure you want to remove all locations from campaign"
    root.table.$("tr").removeClass "selected"

    allLocations = root.table.rows().data() # Then defaults to shows all the locations that are availale

    $('#multi_markers').map ->
      handler = Gmaps.build("Google")
      handler.buildMap
        internal:
          id: "multi_markers"
      , ->
        for aLocation in allLocations
          markers = handler.addMarkers([
            {
              lat: aLocation[9]
              lng: aLocation[10]
            }
          ])
        handler.bounds.extendWith markers
        handler.fitMapToBounds()
        return

我猜您正在寻找 window.confirm 函数。它允许您在确定和取消(在大多数浏览器中)和 returns true 或 false 之间进行选择。

更新

你可以这样用

if(!confirm("Do you want to continue?")) return;

按取消会退出该功能