新窗口打开时选择消失
我目前正在做一个项目,但我陷入了困境。根据客户要求,对现有表格进行了小幅修改。
想象一下 HTML 页面如下:
- 我添加了一个名为 Business Type 的新表单元素,其中有 10 个选项。
- 用户需要选择一个或多个选项并提交,数据将存储在数据库中。数据也存储在数据库中。我已经查过了。
- 表单中还有一个按钮,可以打开一个小窗口来选择一些选项。当此窗口打开时,在业务类型(表单中)中所做的选择就会消失。如何防止这种情况发生?
我正在尝试使用会话。但有没有更好、更简单的方法来实现这一目标呢?我想保留所做的多项选择。
I am currently working on a project and I am stuck. As per client requirements a small modification was made to an existing form.
Imagine the HTML page as follows:
- I have added a new form element named Business Type and there are 10 options in that.
- The user needs to select an option or multiple options and submit and the data would get stored in the database. The data is also getting stored in the database. I have checked that.
- There is also a button within the form which opens up a small window to choose a few options. When this window opens up, the selection made in Business Type (in the form) disappears. How to prevent this from happening?
I am trying to use sessions. But is there a better and easier way to accomplish this? I want to retain the multiple selections that are made.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这一切都可以在客户端完成。基本上,您创建一个包含您想要询问的所有问题的表单,然后使用 JavaScript 显示额外的问题。如果用户没有单击按钮来打开额外的问题,他们只会保留空值。如果他们确实打开了额外的问题,则会在页面上弹出,用户将填写输入。一旦他们回答完这些问题,您只需隐藏它们,但它们仍然保留用户设置的值。
因此,将可选字段放在表单中的隐藏 div 中,然后在单击按钮时显示该 div。
然后,为
#Optional-inputs
提供一些 CSS(或者您可以根据自己的喜好设计样式):对于打开其他问题的按钮/链接,添加一些 JavaScript/jQuery 以将 div 作为绝对定位的窗口。
这会让你大部分时间到达那里。您需要绑定一个事件来触发可选问题框进行保存/关闭 - 这实际上只是隐藏该框并保留用户在表单中设置的值。
This can all be done client-side. Basically, you create a form with all of the questions that you want to ask and then use JavaScript to display extra questions. If the user doesn't click the button to open the extra questions, they just maintain their empty values. If they do open the extra questions, the will pop up on the page and the user will fill in the inputs. Once they are finished with those questions, you simply hide them but they still hold the values that the user set.
So put the optional fields in a hidden div in the form, and then display that div when the button is clicked.
Then, give the
#optional-inputs
some CSS (or you can style it however you like):For the button/link that opens the other questions, add some JavaScript/jQuery to open the div as an absolute positioned window.
This will get you mostly there. You would need to bind an event to trigger the optional questions box to save/close - which is actually just hiding the box and keeping the values that the user set in the form.