简体   繁体   English

jQuery Alert对话框-确认和取消

[英]jQuery Alert Dialog — Confirm and Cancel

I wish to add an alert that pops up upon the selection of the button with id deSelectAll, with the option to confirm, following though on the action, or cancel and return to the page with nothing changing. 我希望添加一个警报,该警报在选择ID为deSelectAll的按钮时弹出,并带有在操作后进行确认的选项,或者取消并返回没有任何更改的页面。 At present I have the following code. 目前,我有以下代码。

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

But all that displays the following result: 但是,所有这些都会显示以下结果:

在此处输入图片说明

I wish to also have the ability to either confirm or cancel the request. 我也希望能够确认或取消该请求。 How can this be implemented? 如何实现呢?

UPDATE : I have added the confirm button, but it does not call the alert at all 更新 :我已经添加了确认按钮,但是它根本没有调用警报

# 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

I guess you are looking for the window.confirm function. 我猜您正在寻找window.confirm函数。 It let you choose between ok and cancel (in most browsers) and returns true or false. 它使您可以在确定和取消之间进行选择(在大多数浏览器中),并返回true或false。

UPDATE 更新

You can use it like that 你可以这样使用

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

It will exit out of the function if you press cancel. 如果按取消,它将退出功能。

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

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