Javascript Javascript警报弹出表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6227507/
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
Javascript alert popup form
提问by Poppy
i have search this whole site and google but cannot find it so, here goes!
我已经搜索了整个网站和谷歌,但找不到它,在这里!
i would like a way to show a form when using alert.
我想要一种在使用警报时显示表单的方法。
for example, when user click post, a dialog pop with asking user a few question like a html form and allow user to click submit or reset or cancel, without loading a new page.
例如,当用户点击帖子时,会弹出一个对话框,询问用户一些问题,如 html 表单,并允许用户点击提交或重置或取消,而无需加载新页面。
i have seen this done but cannot find the same site again.
我已经看到这样做了,但无法再次找到相同的网站。
i have tried putting htm to alert with little success of posting.
我曾尝试将 htm 置于警报状态,但几乎没有发布成功。
any Help is Highly Appreciated!
任何帮助都受到高度赞赏!
回答by Stephen
What you are looking for is a Prompt Box:
您正在寻找的是一个提示框:
<script type="text/javascript">
function show_prompt() {
var name = prompt('Please enter your name','Poppy');
if (name != null && name != "") {
alert(name);
}
}
</script>
example taken from here: http://www.w3schools.com/js/js_popup.asp
回答by Liv
you can do this with jQuery dialogs -- load the dialog on user click and have a form presented in the dialog. have a look at the demos here: http://jqueryui.com/demos/dialog/
您可以使用 jQuery 对话框执行此操作——在用户单击时加载对话框并在对话框中显示一个表单。看看这里的演示:http: //jqueryui.com/demos/dialog/
回答by Andrei Sfat
To complete @Liv's answer you can use jQuery's UI
Reference: Modal Form
要完成@Liv 的回答,您可以使用 jQuery 的 UI 参考: Modal Form
The example shows how to create a new user. It will pop up a dialog where you complete a form and you can submit it or you can cancel it.
该示例显示了如何创建新用户。它将弹出一个对话框,您可以在其中填写表单,您可以提交它,也可以取消它。
Use a modal dialogto require that the user enter data during a multi-step process. Embed form markup in the content area, set the modal option to true, and specify primary and secondary user actions with the buttons option.
使用模态对话框要求用户在多步骤过程中输入数据。在内容区域中嵌入表单标记,将模态选项设置为 true,并使用按钮选项指定主要和次要用户操作。
It pretty much what I understood you need.
这几乎是我所理解的你需要的。
Good luck!
祝你好运!
回答by kirb
HTML can't be placed in system dialogs generated by alert()
, confirm()
or prompt()
. However, you can download jQuery UIand set it up on your Website. (Make sure you have the "dialog" component chosen on the download page.) Then in your JavaScript:
HTML 不能放置在由alert()
、confirm()
或生成的系统对话框中prompt()
。但是,您可以下载jQuery UI并在您的网站上进行设置。(确保您在下载页面上选择了“对话框”组件。)然后在您的 JavaScript 中:
$("<div>Place your HTML here</div>").appendTo("body").dialog({
modal: true,
title: "Enter a title here"
});
Make sure you run this code afterthe page has loaded by using either window.onload
or $(document).ready()
.
确保在运行此代码后,该页面已通过使用加载window.onload
或$(document).ready()
。
Ad@m
广告@m
回答by vindia
You will not be able to do this with alert
, but you should take a look at how to create modal windows.
您将无法使用 执行此操作alert
,但您应该查看如何创建模态窗口。
回答by Jesufer Vn
I recommend you to use a div popup. What you have to do is setting a background on top of all other elements except the div where your form is. The css property display will be set to 'none' until the form is then activated, by setting display = "block". That can be performed using javascript.
我建议您使用 div 弹出窗口。您需要做的是在除表单所在的 div 之外的所有其他元素之上设置背景。通过设置 display = "block",css 属性 display 将被设置为 'none',直到表单被激活。这可以使用javascript来执行。