HTML - 表单提交按钮确认对话框

发布于 2024-09-17 16:34:01 字数 540 浏览 4 评论 0原文

这是一个通用的表单代码

<form name="search_form" action="" method="POST">
<input type="text" name="search_text">          
<input type="submit" name="search_bt" value="Go">
</form>

,有没有办法可以有一个确认对话框,显示“是”\“否”或“确认”\“取消”等...

我想到的一种方法是使用 CSS 层、JavaScript 和 Php ...按钮上有一个 php isset(){} chechk,设置后会显示一个带有两个按钮的 Div 和这些按钮的 onclick=func() JS 函数按钮设置了一个 php 变量(标志),然后我可以 if(flag){} 继续或跳过一些代码...

好吧,这将起作用,而且优点是我可以有一个主题很好的对话框,但我只是想让我的生活更轻松......

this is a general form code

<form name="search_form" action="" method="POST">
<input type="text" name="search_text">          
<input type="submit" name="search_bt" value="Go">
</form>

is there a way could have a confirmation dialog saying 'Yes'\'No' or 'Confirm'\'Cancel' etc...

One way i figured of dong is is with CSS Layer and JavaScript and Php... that have a php isset(){} chechk on the button and when set display a Div displayed with two buttons and onclick=func() JS function of those buttons have a php variable(flag) set and then i can if(flag){} to continue or skip some code...

well that is going to work and plus point is that i can have a well themed dialog box but i just wanna make my life easier...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

忆梦 2024-09-24 16:34:01

您也可以使用表单标签本身中的一行来完成此操作

<form action="exampleHandlerPage.php" method="post" onsubmit="return confirm('Are you sure you want to submit?');">

You can also do it with one line in the form tag itself

<form action="exampleHandlerPage.php" method="post" onsubmit="return confirm('Are you sure you want to submit?');">
梦言归人 2024-09-24 16:34:01

如果一张表单中有 2 个或更多提交按钮:

<input type="submit" value="Edit">
<input type="submit" name="delete" value="Delete" onclick="return confirm('Confirm, please.');">

仅当您单击Delete 按钮时才会显示该对话框。

If you have 2 or more submit buttons in one form:

<input type="submit" value="Edit">
<input type="submit" name="delete" value="Delete" onclick="return confirm('Confirm, please.');">

The dialog shows up only when you click the Delete button.

碍人泪离人颜 2024-09-24 16:34:01

使用原始javascript而不带任何div...

您可以拥有此函数

function confirmSubmit() {
  if (confirm("Are you sure you want to submit the form?")) {
    document.getElementById("FORM_ID").submit();
  }
  return false;
}

并且您可以从表单中的onsubmit事件调用该函数,或者在按钮中的onclick事件上。

顺便说一句,您听说过 JQuery。它是一个 JS 库,包含许多有用的东西,为您提供一种舒适而美观的 javascript 编码方式。

作为您想要完成的操作的示例,请使用以下确认对话框: a href="http://jquery.com/" rel="nofollow noreferrer">JQuery 为例

Using raw javascript without any div...

You can have this function

function confirmSubmit() {
  if (confirm("Are you sure you want to submit the form?")) {
    document.getElementById("FORM_ID").submit();
  }
  return false;
}

And you can call that function from the onsubmit event in the form, or on the onclick event in the button.

By the way, have you heard about JQuery. Its a JS Library with a lot of helpful things that give you a comfort and beauty way of coding javascript.

As an example of what you want to get done, take this confirmation dialog from JQuery as example

贱贱哒 2024-09-24 16:34:01
<form action="<form handler>" method="post" onsubmit="return confirm('Are you sure you want to submit?')">

这个 javascript 是否可以存储与标签“form”不同的内容,替换

return confirm(...)

为类似的内容

return sendata(...)
<form action="<form handler>" method="post" onsubmit="return confirm('Are you sure you want to submit?')">

is this javascript can be store diferent from tag "form", replace

return confirm(...)

with something like

return sendata(...)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文