提交表单时更改 CSS 规则?
我有一个 HTML 页面(我们称之为 apdivs.html),其中有 9 个包含图像的 AP Div。 这些 AP Div 被设置为“隐藏”(可见性:隐藏;),以便它们包含的图像不会显示在页面上。
对于每个 AP Div,我都有一个包含表单的 HTML 文件和一个 PHP 文件,当用户提交表单时,该文件会通过电子邮件向我发送表单的内容。 所以我有 1.html-9.html 和 1.php-9.php。
我需要的是当用户提交表单时,相应AP Div上的可见性规则从隐藏更改为可见。
我需要它为所有用户永久更改,所以我想我需要它来实际更改服务器上的 HTML 文件。
举例来说...
如果用户点击 7.html 上表单上的提交按钮,则 CSS 规则“visibility:hidden;” apdivs.html 上的第 7 个 AP Div 更改为“可见性:可见;”
这怎么能做到呢?我假设我需要使用 PHP,如果是这样,如何使用 PHP 来完成此操作?
I have a HTML page (lets call it apdivs.html) with 9 AP Divs containing an image.
These AP Divs are set to 'hidden' (visibility: hidden;) so that the image they contain is not shown on the page.
For each of these AP Divs I have a HTML file containing a form and a PHP file that emails me the content of the form when the user submits the form.
So I have 1.html-9.html and 1.php-9.php.
What I need is when the user submits a form, the visibility rule on the corresponding AP Div is changed from hidden to visible.
I need it to change PERMANENTLY for ALL USERS, so I think I need it to actually change the HTML file on the server.
So for example...
If the user hits the submit button on the form on 7.html, the CSS rule 'visibility: hidden;' on the 7th AP Div on apdivs.html changes to 'visibility: visible;'
How can this be done? I assume I will need to use PHP, if so how can this be done using PHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否考虑过使用 MySQL 数据库来跟踪应该隐藏或可见的内容,而不是尝试更改服务器上的 HTML 文件?当用户提交表单时,您可以更新一行来跟踪要显示的内容和要隐藏的内容。您还可以跟踪正在提交的表单的内容,以便数据不仅仅存在于电子邮件中。
Instead of trying to change the HTML file on the server, have you considered using a MySQL database to keep track of what should be hidden or visible? When the user submits the form, you could update a row that keeps track of what to show and what to hide. You could also keep track of the contents of the form being submitted, so that the data is not just in an email.
对于您的特定情况,您可以使用透明 PNG 图像,而不是使用“可见性:隐藏”。这也使得 PHP 表单提交处理更简单,因为您只需要替换图像目录中的图像,而不是使用数据库来跟踪哪些 div 可见、哪些 div 隐藏。
For your particular case, instead of using "visibility: hidden", you can use transparent PNG image. This makes the PHP form submission handling simpler as well, as you will only need to replace the images in image directory, instead of using a database to keep track which divs are visible and which are hidden.