简体   繁体   中英

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. 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. It let you choose between ok and cancel (in most browsers) and returns true or 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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