In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "javascript how to construct form forms that can upload files". In daily operation, I believe many people have doubts about how javascript constructs form forms that can upload files. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how javascript constructs form forms that can upload files". Next, please follow the editor to study!
When uploading files, we all know that we need to add enctype= "multipart/form-data" to the form form. During the development process, you may also encounter situations where you need to construct form forms with javascripts. For general javascript to construct form, you can use the following methods:
Var form = document.createElement ('form')
Form.id= "the_form"
Form.action= "/ img.php"
Form.method='post'
Form.name= "the_form_"
When the form constructed by javascript needs to upload files, it thought that adding a form.enctype= "multipart/form-data" directly would solve the problem, but found that this was not the case. Search for some reasons from the Internet, and finally find the solution. The original javascript form object name should not be enctype, but should be encding, instead of form.encding= "multipart/form-data", the problem is solved.
You can use the following code to place the form in a HTML tag:
Var parNode = document.getElementById ("plus")
ParNode.appendChild (form); / / add form form to plus, and plus is a layer in html
You can also put input, checkbox, and other forms in the form. You can use the following code to change the type and value of the form through its object:
Var input=document.createElement ("input")
Input.id= "upfile_1"
Input.name= "upfile_1"
Input.type= "file"
Input.className= "file_upload"
The upload_pic () function is called when input.onchange=function () {/ / clicks on the form
Upload_pic ()
}
Form.appendChild (input); / / append input form to form
At this point, the study on "how to construct javascript form forms that can upload files" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.