使用 JavaScript 提示显示选项列表 [英] Show list of options using JavaScript prompt
本文介绍了使用 JavaScript 提示显示选项列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 JavaScript 中,是否可以使用 prompt
窗口显示要单击的选项列表,而不是要手动输入的选项列表?
我想将每个选项显示为一个按钮,而不是要求用户手动输入选项(如下所示):
var OptionChosen = prompt('输入 1、2、3 或 4:')
解决方案
你不能这样做,但你可以使用 jQuery 对话框.
示例 jQuery:
var selected = 0;$('#dialog').dialog({title: "提示",纽扣: {第一":函数(){选择 = 1;},第二":函数(){选择 = 2;},第三":函数(){选择 = 3;},第四":函数(){选择 = 4;}//.....................}});
使用 html:
<p>选择您的选项</p>
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:')
解决方案
You can't do that, but you could use jQuery dialog box instead.
Example 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:
<div id="dialog">
<p>Choose your option</p>
</div>
这篇关于使用 JavaScript 提示显示选项列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文