简体   繁体   English

如何在警报框中显示单选按钮

[英]How to display radio button on an alert box

Is it possible to have a radio button in an alert box? 警报框中是否可以有一个单选按钮? The requirement is, not to use any modal box, that why we just think if it's possible with alert box or confirm box. 要求是,不要使用任何模式框,这就是为什么我们只考虑是否可以使用警报框或确认框。 then we can good to go. 那我们就可以走了。

Any help will appreciate. 任何帮助将不胜感激。 Sample Screenshot is below. 示例屏幕截图如下。

在此处输入图片说明

i don't guess. 我不猜。 i know that this is in fact impossible. 我知道这实际上是不可能的。 the reason is simple: 原因很简单:

alert() , prompt() aswell as confirm() were part of html + js since js exists. 因为js存在,所以alert()prompt() Confirm confirm()都是html + js的一部分。
they never got deprecated though they break the asyncronous flow of javascript. 尽管它们打破了javascript的异步流程,但它们从未被弃用。

this is essentially why they only allow you to play around with strings. 从本质上讲,这就是为什么它们只允许您使用弦乐的原因。
they were never intended to be feature rich. 他们从来都不打算成为功能丰富的人。
they were actually invented out of the blue because the inventor (Brendan Eich) thought they'd come in handy. 实际上,它们是突然被发明的,因为发明者(Brendan Eich)认为它们会派上用场。 (wich at that time was more than enough for everyone) (那时的每个人都绰绰有余)

they are by design blocking operations and should be avoided as much as possible. 它们是设计使然的操作,应尽量避免。

to get around them simply create a so called modal dialog (thats basically a <div> with position: fixed above the pages content. 要解决这些问题,只需创建一个所谓的模式对话框(基本上是一个<div> ,其position: fixed在页面内容上方。

benefit: 效益:
you can easily make it appear as you want and you would not break any network connections or behavior of your application. 您可以轻松地使其按需显示,并且不会中断任何网络连接或应用程序的行为。

PS: PS:
don't use w3schools as reference for learning or anything else. 不要将w3schools用作学习或其他参考。
they are a low quality database. 他们是一个低质量的数据库。 you should look stuff up on mdn or other sites but should seriously avoid w3schools since it's not feature complete on any topic. 您应该在mdn或其他网站上查找内容,但应避免使用w3schools,因为它在任何主题上均不完整。
keep in mind this is an opinion. 请记住,这是一种意见。

It is impossible to use radio inside of alert window. 无法在警报窗口内使用收音机。

Message parameter in window.alert(message); window.alert(message);消息参数window.alert(message); has a string type and you cannot put Object or HTML there (will be transfomed to string). 具有字符串类型,您不能在其中放置对象或HTML(将转换为字符串)。

Do not overuse window.prompt() Method , as it prevents the user from accessing the other parts of the page until the box is closed. 不要过度使用window.prompt()方法,因为在框关闭之前,它会阻止用户访问页面的其他部分。

Window prompt Usage Note 窗口提示用法说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM