简体   繁体   English

动态添加额外的输入字段到html表单

[英]Dynamically add extra input fields to html form

I am currently working on an html and php project. 我目前正在研究html和php项目。 What I want to be able to do is to have an html with a file chooser for selecting a screenshot. 我想要做的是拥有一个带有文件选择器的html来选择屏幕截图。 Next to the file chooser will be a button/link for the user to be able to add another field. 文件选择器旁边将是一个按钮/链接,供用户添加其他字段。 When the user clicks on the button or link I want another field to be added to the form underneath the first field, then the user can press the button/link again and another field is added all. 当用户单击按钮或链接时,我希望将另一个字段添加到第一个字段下方的表单中,然后用户可以再次按下按钮/链接,然后将另一个字段全部添加。 Then when the form is submitted it gets the value of all the input fields including all the files to be uploaded that were added to the form. 然后,在提交表单时,它将获得所有输入字段的值,包括已添加到表单的所有要上传的文件。

What is the best method to achieve this, I assume javascript and/or jquery might be involved. 实现此目的的最佳方法是什么,我假设可能涉及javascript和/或jquery。

Thanks for any help you can provide. 感谢您的任何帮助,您可以提供。

UPDATE I have found out how to do it but I was wondering instead how to make it fade in or make it smoothly slide the rest of the form down. 更新我已经找到了解决方法,但是我想知道如何使它淡入或平滑地将表单的其余部分向下滑动。 I have added the fields inside a div and done javascript that makes the input field appear inside this div but it just appears, I want it to have a smooth fade in animation instead of it just flashing up on the screen. 我已经在div中添加了字段并完成了javascript,使输入字段出现在该div中,但它只是出现了,我希望它在动画中具有平滑的淡入淡出效果,而不是仅在屏幕上闪烁。 Below is the javascript that I have used to add the input field 以下是我用来添加输入字段的JavaScript

<script>
        function addFields()
        {
            document.getElementById("screenshotFields").innerHTML += "<input class=\"fields\" type=\"file\" name=\"filScreenshot[]\" />";
        }
    </script>

您需要本教程称为“多文件上传魔术”的东西。

答案是从@ott评论到我的问题到另一个stackoverflow问题

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

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