【问题标题】:jQuery Alert Dialog -- Confirm and CanceljQuery 警报对话框 -- 确认和取消
【发布时间】:2015-01-07 01:53:49
【问题描述】:

我希望添加一个警报,该警报会在选择 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

【问题讨论】:

    标签: javascript jquery dialog alert


    【解决方案1】:

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

    更新

    你可以这样使用它

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

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

    【讨论】:

    • 如何在考虑到操作的情况下实现这一点?查看更新的问题
    • 你的意思是forms action with action吗?
    • 查看更新后的代码,我希望调用页面加载时看到的操作来重置地图
    • 使用此代码按取消不会取消该操作,它仍然允许该操作。我希望取消按钮取消对话框中的操作
    • 您没有在代码中添加 if 和 return。
    猜你喜欢
    • 2011-08-10
    • 1970-01-01
    • 2019-04-27
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-27
    相关资源
    最近更新 更多