使用 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
Show list of options using JavaScript prompt
提问by Anderson Green
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?
在 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>