//新建空formData var formData = new FormData(); //基於 form 元素建立formData var formData1 = new FormData(form); //添加字段方法1 formData.append("name","gaoxiong"); formData.append("age",20); formData.append("family","fengxujiao"); formData.append("family","baba"); formData.append("family","mama"); //添加字段方法1,當value爲file時,filename默認值爲file.filename,當value爲blob對象時,filename爲"blob" formData.append(key,value,filename); //遍歷字段 for( var pair of formData.entries()){ console.log(pair[0]+","+pair[1]); }; //刪除字段 formData.delete("name"); //FormData的get()方法用於返回FormData對象中和指定的鍵關聯的第一個值,若是你想要返回和指定鍵關聯的所有值,那麼能夠使用getAll()方法。 formData.get("age"); //獲取與key關聯的全部value formData.getAll("age"); //判斷是否含有key formData.has(name); //遍歷全部key for (var key of formData.keys()) { console.log(key); } //重置字段,會將選定的字段先刪除,在從新添加(注意與append的區別) formData.set("family","gaoxiong"); for( var pair of formData.entries()){ console.log(pair[0]+","+pair[1]); }; //獲取全部values for (var key of formData.values()) { console.log(key); };