JavaScript alert with 3 buttons

后端 未结 4 1212
你的背包
你的背包 2021-01-04 05:41

I have a JavaScript alert button that appears on the website when a user is going to proceed to a signup page.

It looks something like this

Would you like

相关标签:
4条回答
  • 2021-01-04 06:23

    Unfortunately, I don't think you can change the number of buttons in an alert box. (At least not in any browser that I know of.) You can use one of the many modal dialog scripts that are out on the net. Something like Eric Martin's SimpleModal Dialog for jquery would probably work.

    They basically take a div and style it up with css and javascript to mimic a dialog box.

    0 讨论(0)
  • 2021-01-04 06:25

    No.

    You need to use a custom modal dialog, such as jQuery UI Dialog.

    0 讨论(0)
  • 2021-01-04 06:30

    however you can use confirm function.. but NOT three buttons.

    var r=confirm("Press a button!");
    if (r==true)
      {
      x="You pressed OK!";
      }
     else
      {
      x="You pressed Cancel!";
      }
    
    0 讨论(0)
  • 2021-01-04 06:30

    Nowdays, you can use an HTML dialog element.

    <dialog open>
      <p>Greetings, one and all!</p>
      <button>Ok</button><button>Maybe</button><button>Cancel</button>
    </dialog>
    

    And do what you want with it.

    document.querySelectorAll('button').forEach($button => 
      $button.onclick = () => document.querySelector('dialog').removeAttribute('open'))
    

    https://jsfiddle.net/6nus2zt4/1/

    Hope this help to future generations :)

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