如何在action标记中传递参数

how to pass parameter in action tag?

本文关键字:参数 action      更新时间:2023-09-26

我想将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();

在提交之前设置操作属性:

var form = document.forms["form"];
form.action = res;
form.submit();

如果用户可以手动提交此表单,则可以使用onsubmit事件:

form.onsubmit = function(){
    this.action = res;
};