JS表单提交
1、在html中的表单form设置属性action='#'防止自动提交
2、利用js获取html中表单form,重新设置表单的action
3、action设置完毕后调用form.submit()方法提交表单
4、表单提交后利用window.close()关闭当前窗口
button按钮也可以的啊,一样的使用方法啊,在js中提交的,还是说你想根据不同的按钮将form1表单提交到不同的action里?
<script type="text/javascript">
function sub(){
document.form1.submit();
}
</script>
<body>
<form action="Getvalue" method="post" name="form1">
<input type="text" name="username"><br/>
<input type="password" name="password"><br/>
<input type="button" value="button测试" onclick="sub();">
</form>
</body>
js 提交表单数据: 附件+对象的的多集合在我们前端进行表单提交的时候,有时候会出现这种情况:Failed to convert java.lang.String to java.util.List
等等。
例如:
我后台定义一个对象:
examPaper 包含 String userId,Float userScore, MultipartFile examFile 用户id ,试卷分数,试卷文件
对象外面 classPaper有: String classId String className List<examPaper> examPaperList
这个时候,后台接收为 ClassPaper
如果按照平常的 form-data 提交 则应按以下方式提交:
let fd = new FormData();
fd.append("classId ",classId );
fd.append("className ",className );
examPaperList.forEach((item,index) ->{
fd.append("examPaperList["+index+"].userId",item.userId);
fd.append("examPaperList["+index+"].userScore",item.userScore);
fd.append("examPaperList["+index+"].examFile ",item.examFile );
});
以这种方式就可以实现 多附件 一一 对应提交。以避免对象转换错误问题。