jQuery Alert对话框 - 确认并取消

时间:2015-01-07 01:53:50

标签: jquery alertdialog

我希望添加一个警报,在选择带有id deSelectAll的按钮时弹出,并提供确认选项,然后执行操作,或者取消并返回到没有任何更改的页面。目前我有以下代码。

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

但所有这些都显示以下结果:

enter image description here

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

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

# 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

1 个答案:

答案 0 :(得分:0)

我猜您正在寻找window.confirm功能。它允许您在ok和cancel之间进行选择(在大多数浏览器中)并返回true或false。

<强>更新

你可以像那样使用它

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

如果按取消,它将退出该功能。