我想将res
变量作为表单操作传递。这可能与HTML有关吗?
<script>
var name =$("#name").val();
var file =$("#file").val();
var res= localhost:8080 + "/test/reg?&name="+name+"&file=" +file ;
</script>
<form action="res" id ="form" method="post" enctype="multipart/form-data">
Name:<input type="text" name="name" id="name"/>
Upload:<input type="file" name="file" id="file"/>
</form>
document.forms["form"].submit();
答案 0 :(得分:1)
在提交之前设置action属性:
var form = document.forms["form"];
form.action = res;
form.submit();
如果用户可以手动提交此表单,则可以使用onsubmit
事件:
form.onsubmit = function(){
this.action = res;
};