form表单提交时,action怎么带参数
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
form表单提交时,action怎么带参数
在提交form表单的时候,action 不填就默认为提交到当前的页⾯。
今天遇到的当前页⾯是已经带了参数了,⽐如:/index.php? id=1,按照action留空的⽅法来提交,就不能提交到这个带参数的url了,也不能到把表单中的直拼接在uri后⾯。
那怎么办呢,可以⽤js的⽅法拼接好在submit
<body>
<form action="ss.do?" method="get">
<input type="text" id ="input"/>
<input type="button" value="提交" onClick="test()">
</form >
</body>
<script>
function test(){
var f = document.getElementsByTagName("form")[0];
f.action=f.action+"id="+document.getElementById("input").value;
alert(f.action);
}
</script>
原⽂连接:
这种⽅法在每次提交的时候,会⼀直拼接uri,在我的项⽬上⽤不了,不过给了我启发,那就是js中重定向,代码如下:
<form action="" method="get">
<input type='text' name='gid'/>
<input type='text' name='type'/>
<input type="button" value="搜索" onClick="tpformsubmit()">
</form>
<script>
function tpformsubmit(){
var gid = $('input[name=gid]').val();
var type = $('input[name=type]').val();
url = '/index/web?style=tp&gid='+gid+'&type='+type;
window.location.href = url;
}
</script>。