我如何使用 3 个复选框/单选按钮作为选项在 javascript 中创建提示?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6024716/
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
how do i create a prompt in javascript with 3 checkboxes/radio buttons as choices?
提问by Incognito
How do I create a javascript prompt box where you have to select 1 of 3 choices? I'm looking to do something similar to a html form's radio buttons except within a javascript prompt.
如何创建一个 javascript 提示框,您必须在其中选择 3 个选项之一?我希望做一些类似于 html 表单的单选按钮的事情,除了在 javascript 提示中。
采纳答案by Code Maverick
You could use jQuery and do a 3 button dialog(). Check out this working jsFiddle demo:
您可以使用 jQuery 并执行 3 按钮对话框()。看看这个有效的 jsFiddle 演示:
$("#dialog").dialog({
autoOpen: true,
buttons: {
Yes: function() {
alert("Yes!");
$(this).dialog("close");
},
No: function() {
alert("No!");
$(this).dialog("close");
},
Maybe: function() {
alert("Maybe!");
$(this).dialog("close");
}
},
width: "400px"
});
回答by Z. Zlatev
This can't be achieved natively as .prompt()
. This functionality requires more advanced JS. Here are some libs to mess with:
这不能像.prompt()
. 此功能需要更高级的 JS。这里有一些需要处理的库:
Could be more adequate ones out there. Been a while using such stuff
那里可能有更合适的。有一段时间使用这样的东西
回答by Stephen
You can't do this from an "alert" box if thats what you mean.. But you could use any number of libraries to create a popup window which is basically just a and do your form within there.
如果这就是您的意思,您不能从“警报”框中执行此操作。但是您可以使用任意数量的库来创建一个弹出窗口,该窗口基本上只是一个并在其中执行您的表单。
You could then tie a button or whatever to a function which closes the box and parses the form into your structures within Javascript.
然后,您可以将按钮或其他任何东西绑定到关闭框并将表单解析为您在 Javascript 中的结构的函数。