当前位置:网站首页>Use of formdata object, VAR formdata=new formdata()
Use of formdata object, VAR formdata=new formdata()
2022-07-28 14:31:00 【CDamogu】
brief introduction
FormData Use of objects :
- Use some key value pairs to simulate a series of form controls : the form Of form elements in name And value Assemble into one queryString
- Upload binaries asynchronously
FormData Object operation method , All in the prototype , I don't have any properties or methods
Proto: FormData
Create an empty object
// adopt FormData Constructor creates an empty object
var formdata=new FormData();
// Can pass append() Method to append data
formdata.append("name","laotie");
// adopt get Method to read the value
console.log(formdata.get("name"));//laotie
// adopt set Method to set the value
formdata.set("name","laoliu");
console.log(formdata.get("name"));//laoliu
Through the form to FormData initialization
<form id="advForm">
<p> Advertising name :<input type="text" name="advName" value="xixi"></p>
<p> Advertising category :<select name="advType">
<option value="1"> Shuffling figure </option>
<option value="2"> At the bottom of the carousel </option>
<option value="3"> Hot recycling ads </option>
<option value="4"> Select ads for premium products </option>
</select></p>
<p><input type="button" id="btn" value=" add to "></p>
</form>
// Using form elements as parameters , Realize to formData The initialization :
// Get form button elements
var btn=document.querySelector("#btn");
// Add click event for button
btn.onclick=function(){
// according to ID Get the form Form Elements
var form=document.querySelector("#advForm");
// Take the resulting form element as an argument , Yes formData To initialize
var formdata=new FormData(form);
// adopt get Methods to get name by advName Elemental value value
console.log(formdata.get("advName"));//xixi
// adopt get Methods to get name by advType Elemental value value
console.log(formdata.get("advType"));//1
}
get(key) getAll(key) To get the corresponding value
// obtain key by age First value of
formdata.get("age");
// obtain key by age All values , The return value is an array type
formdata.getAll("age");
adopt append(key,value) Appending data at the end of the data
// adopt FormData Constructor creates an empty object
var formdata=new FormData();
// adopt append() Method appends key by name The value is laoliu The data of
formdata.append("name","laoliu");
// adopt append() Method appends key by name The value is laoli The data of
formdata.append("name","laoli");
// adopt append() Method appends key by name The value is laotie The data of
formdata.append("name","laotie");
// adopt get Method reading key by name First value of
console.log(formdata.get("name"));//laoliu
// adopt getAll Method reading key by name All values
console.log(formdata.getAll("name"));//["laoliu", "laoli", "laotie"]
adopt set(key, value) To set and modify data
//key Does not exist , A piece of data will be added
// adopt FormData Constructor creates an empty object
var formdata=new FormData();
// If key The value of does not exist and will add a key by name The value is laoliu The data of
formdata.set("name","laoli");
// adopt get Method reading key by name First value of
console.log(formdata.get("name"));//laoli
key Value of exists , The corresponding value value
// adopt FormData Constructor creates an empty object
var formdata=new FormData();
// adopt append() Method appends key by name The value is laoliu The data of
formdata.append("name","laoliu");
// adopt append() Method appends key by name The value is laoliu2 The data of
formdata.append("name","laoliu2");
// adopt get Method reading key by name First value of
console.log(formdata.get("name"));//laoliu
// adopt getAll Method reading key by name All values
console.log(formdata.getAll("name"));//["laoliu", "laoliu2"]
// There will be key by name Is changed to laoli
formdata.set("name","laoli");
// adopt get Method reading key by name First value of
console.log(formdata.get("name"));//laoli
// adopt getAll Method reading key by name All values
console.log(formdata.getAll("name"));//["laoli"]
adopt has(key) To determine whether there is a corresponding key value
// adopt FormData Constructor creates an empty object
var formdata=new FormData();
// adopt append() Method appends key by name The value is laoliu The data of
formdata.append("name","laoliu");
// Judge whether it includes key by name The data of
console.log(formdata.has("name"));//true
// Judge whether it includes key by age The data of
console.log(formdata.has("age"));//false
adopt delete(key) You can delete data
// adopt FormData Constructor creates an empty object
var formdata=new FormData();
// adopt append() Method appends key by name The value is laoliu The data of
formdata.append("name","laoliu");
console.log(formdata.get("name"));//laoliu
// Delete key by name Value
formdata.delete("name");
console.log(formdata.get("name"));//null
边栏推荐
- [translation] salt companies come to linkerd for load balancing, and stay for efficiency, reliability and performance
- Summarize the knowledge points of the ten JVM modules. If you don't believe it, you still don't understand it
- 朗镜科技(Trax中国)“机器人+AI”开启中国零售元宇宙时代
- 【Utils】JsonUtil
- js的实例化方式
- 468 product planning and promotion plan (150 copies)
- 超好用的手机录屏软件推荐
- Super resolution reconstruction based on deep learning
- These three online PS tools should be tried
- Excel VBA 开发过程中遇到的一些问题,解决方案,持续更新
猜你喜欢

Install mysql5.7.36 in CentOS

ScottPlot入门教程:获取和显示鼠标处的数值

ZABBIX distributed

These three online PS tools should be tried

Literature reading (245) roller

如何只降3D相机不降UI相机的分辨率

HCIP第十天

草料二维码--在线二维码生成器

Career planning of Software Test Engineer

Revised version | target detection: speed and accuracy comparison (faster r-cnn, r-fcn, SSD, FPN, retinanet and yolov3)
随机推荐
Afnetworking crash course
[ecmascript6] other new interface features
(function(global,factory){
2022 high altitude installation, maintenance, removal of examination question bank and online simulated examination
软件测试的发展与定义
C# 获取当前路径7种方法
String转为long 类型报错原因:要转为long必须是int、double、float型[通俗易懂]
如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然
Brief introduction of diversity technology
PowerDesigner creates a database model (conceptual model example)
2022 melting welding and thermal cutting examination questions and online simulation examination
Foundation of deep learning ---- GNN spectral domain and airspace (continuous improvement, update and accumulation)
指针和数组(7)
天气这么热太阳能发电不得起飞喽啊?喽啊个头……
Pointers and arrays (7)
[ecmascript6] modularization
Floating point data type in C language (did you learn to waste it)
Why is it reverse to convert from other formats to BMP
58子站安居,经纪人营销管理平台登录接口加密逆向
[translation] salt companies come to linkerd for load balancing, and stay for efficiency, reliability and performance