简体   繁体   English

将类型文件的输入追加到表单jquery中

[英]Append input of type file into form jquery

Below is the piece of code that i have written, 以下是我编写的一段代码,

var form = $('<form/>', {action : 'myServlet', method : 'POST', name : 'myForm', id: 'myForm'}).appendTo('body');
form.append("<textarea name='description' id='description' value=''/>");
form.append("<textarea name='title' id='title' value=''/>");

$('#description').val($scope.rsp.observations);
$('#title').val($scope.rsp.title);
$('#myForm').submit();

Now I have to add an input of type file into this form and append, and also i have to save a file in this tag. 现在,我必须将类型文件的输入添加到此表单中并追加,并且还必须在此标签中保存文件。 How can this be done so that my output looks like 如何做到这一点,以便我的输出看起来像

<form id="myForm" method="post" action="myservlet">
    <input type="file" name="attachment">
    <textarea name="description" id="description">
    <textarea name="title" id="title">
</form>

Here the input file type must contain a file stored in a variable. 在此,输入文件类型必须包含存储在变量中的文件。

You must need to select file manually to upload due to security reason, here you can create and append input field file. 由于安全原因,您必须手动选择文件才能上载,在这里您可以创建和附加输入字段文件。 but can't send hard code value or path to server. 但无法将硬代码值或路径发送到服务器。

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

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