在提交form表单的时候,action 不填就默认为提交到当前的页面。今天遇到的当前页面是已经带了参数了,比如:www.xxx.com/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>
原文连接:http://zhidao.baidu.com/question/465627004.html
这种方法在每次提交的时候,会一直拼接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>