2014-10-17 57 views
1

我想通过res变量作为表单动作。这可能与HTML?如何在action标签中传递参数?

<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(); 

回答

1

提交前设置action属性:

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

如果用户可以提交此表手动,那么你可以使用onsubmit事件:

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