Him*_*mad 5 html javascript forms
因此,我有一个表单,其中包含代表教育信息的两组相同的输入。可能有两个以上,因为我想添加一个按钮来创建一个新组,以便用户可以像在 LinkedIn 中一样输入他所有的教育背景。
\n\n<form id="formCV" action="">\n <div id="educationContainer">\n <!-- First Group -->\n <div class="education">\n <div>\n <input type="text" name="institutionName">\n </div>\n <div>\n <input type="text" name="courseName">\n </div>\n <div>\n <input type="month" name="startDate">\n </div>\n <div>\n <input type="month" name="endDate">\n </div>\n </div>\n <!-- Second Group -->\n <div class="education">\n <div>\n <input type="text" name="institutionName">\n </div>\n <div>\n <input type="text" name="courseName">\n </div>\n <div>\n <input type="month" name="startDate">\n </div>\n <div>\n <input type="month" name="endDate">\n </div>\n </div>\n </div>\n</form>\n
Run Code Online (Sandbox Code Playgroud)\n\n现在,如果我使用 FormData API 来获取表单数据,如下所示:
\n\nfor(let entry of formData.entries()){\n console.log(entry);\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n我得到以下输出:
\n\n(2)\xc2\xa0["institutionName", "Harvard"]\n(2)\xc2\xa0["courseName", "Web Development"]\n(2)\xc2\xa0["startDate", "2000-11"]\n(2)\xc2\xa0["endDate", "2008-11"]\n(2)\xc2\xa0["institutionName", "Oxford"]\n(2)\xc2\xa0["courseName", "Business Management"]\n(2)\xc2\xa0["startDate", "2009-10"]\n(2)\xc2\xa0["endDate", "2010-05"]\n
Run Code Online (Sandbox Code Playgroud)\n\n我想要实现的是以有组织的方式获得输出,如下所示:
\n\neducation:[\n {\n institutionName:"Harvard",\n courseName:"Web Development",\n startDate:"2000-11",\n endDate:"2008-11"\n },\n {\n ...\n }\n]\n
Run Code Online (Sandbox Code Playgroud)\n\n所以我有兴趣了解实现这一目标的最佳方法。预先感谢您的任何帮助!
\n 归档时间: |
|
查看次数: |
1812 次 |
最近记录: |