繁体   English   中英

jQuery Alert对话框-确认和取消

[英]jQuery Alert Dialog — Confirm and Cancel

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

$("#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函数。 它使您可以在确定和取消之间进行选择(在大多数浏览器中),并返回true或false。

更新

你可以这样使用

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM