简体   繁体   English

Javascript 警报弹出表单

[英]Javascript alert popup form

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!非常感谢任何帮助!

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示例取自这里: http://www.w3schools.com/js/js_popup.asp

you can do this with jQuery dialogs -- load the dialog on user click and have a form presented in the dialog.您可以使用 jQuery 对话框来执行此操作——在用户单击时加载对话框并在对话框中显示一个表单。 have a look at the demos here: http://jqueryui.com/demos/dialog/看看这里的演示: http://jqueryui.com/demos/dialog/

To complete @Liv's answer you can use jQuery's UI Reference: Modal Form要完成@Liv 的回答,您可以使用 jQuery 的 UI Reference: 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 dialog to 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.在内容区域嵌入表单标记,将 modal 选项设置为 true,并使用按钮选项指定主要和次要用户操作。

It pretty much what I understood you need.这几乎是我理解你需要的。

Good luck!祝你好运!

HTML can't be placed in system dialogs generated by alert() , confirm() or prompt() . HTML 不能放置在由alert()confirm()prompt()生成的系统对话框中。 However, you can download jQuery UI and set it up on your Website.但是,您可以下载jQuery UI并在您的网站上进行设置。 (Make sure you have the "dialog" component chosen on the download page.) Then in your JavaScript: (确保您在下载页面上选择了“对话框”组件。)然后在您的 JavaScript 中:

$("<div>Place your HTML here</div>").appendTo("body").dialog({
     modal: true,
     title: "Enter a title here"
});

Make sure you run this code after the page has loaded by using either window.onload or $(document).ready() .确保在页面加载使用window.onload$(document).ready()运行此代码。

Ad@m广告@m

You will not be able to do this with alert , but you should take a look at how to create modal windows .您将无法使用alert执行此操作,但您应该查看如何创建模态 windows

I recommend you to use a div popup.我建议您使用 div 弹出窗口。 What you have to do is setting a background on top of all other elements except the div where your form is.您需要做的是在除表单所在的 div 之外的所有其他元素之上设置背景。 The css property display will be set to 'none' until the form is then activated, by setting display = "block". css 属性显示将设置为“无”,直到随后激活表单,通过设置 display =“block”。 That can be performed using javascript.这可以使用 javascript 来执行。

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

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