使用 JavaScript 提示显示选项列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16556030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 05:07:05  来源:igfitidea点击:

Show list of options using JavaScript prompt

javascriptprompt

提问by Anderson Green

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

在 JavaScript 中,是否可以使用prompt窗口显示要单击的选项列表,而不是要手动输入的选项列表?

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:')

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

回答by PSR

You can't do that, but you could use jQuery dialog boxinstead.

你不能这样做,但你可以使用jQuery 对话框代替。

Example jQuery:

示例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;
    }
    // ..............
  }
});

with html:

使用 html:

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