How to add event listener for html buttons in sweetalert dialog box in jquery

后端 未结 1 784
悲&欢浪女
悲&欢浪女 2021-01-03 08:43

I am using SweetAlert box and I have three buttons, which i created using html inputs but I need to have three different click event listener performing different actions on

1条回答
  •  隐瞒了意图╮
    2021-01-03 09:31

    Buttons are created on run-time hence you will need event delegation

    Note: If you attach events this ways, they will be attached every time sweet alert is invoked. Bind then out of swal initialization.

    Try this:

    $("#btnProcessRequest").click(function(e) {
      e.preventDefault();
      var btn = "button";
      swal({
        title: "HTML Consultation Review!",
        text: ' ' +
          ' ' +
          '',
        html: true,
        showConfirmButton: false
      });
    });
    $(document).on('click', "#btnA", function() {
      alert(this.id);
    });
    
    $(document).on('click', "#btnB", function() {
      alert(this.id);
    });
    
    $(document).on('click', "#btnC", function() {
      alert(this.id);
    });
    
    
    
    

    0 讨论(0)
提交回复
热议问题