Mostrar la lista de opciones mediante el indicador de JavaScript

In JavaScript, is it possible to show a list of options to click using a prompt window, instead of a list of options to be typed in manually?

I'd like to present each option as a button, instead of asking the user to type the options manually (as shown here):

var OptionChosen = prompt('Enter 1, 2, 3, or 4:')

preguntado el 15 de mayo de 13 a las 03:05

Proper, browser-based custom modal dialogs are impossible to create - aparentemente due to security concerns. You'd have to mimic one using a DOM element. -

Is it compulsory for you to use a prompt? I would just code my own popup using javascript and a DOM element. You also have fancy popup libraries for jquery -

@AntonGarciaDosil Specifically, I want to create a modal dialog box with a list of buttons that the user can select, so that the value of a variable is set based on the user's choice (just like the JavaScript prompt window). -

@AndersonGreen I believe you cannot do that with a Javascript prompt. As PSR said you may use jQuery dialog. There is a huge amount of jQuery extensions implementing modal windows. -

1 Respuestas

You can't do that, but you could use cuadro de diálogo jQuery preferiblemente.

Ejemplo de jQuery:

var selected = 0;
$('#dialog').dialog({
  title: "Prompt",
  buttons: {
    "First": function() {
      selected = 1;
    },
    "Second": function() {
      selected = 2;
    },
    "Third": function() {
      selected = 3;
    },
    "Fourth": function() {
      selected = 4;
    }
    // ..............
  }
});

con html:

<div id="dialog">
    <p>Choose your option</p>
</div>

Respondido 28 ago 18, 02:08

Is it possible to set a variable to the output of a JQuery dialog box? - anderson verde

You can have different buttons here.You can set return differenbt values - PSR

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.