form表单提交时,action怎么带参数

在提交form表单的时候,action 不填就默认为提交到当前的页面。今天遇到的当前页面是已经带了参数了,好比:www.xxx.com/index.php?id=1,按照action留空的方法来提交,就不能提交到这个带参数的url了,也不能到把表单中的直拼接在uri后面。那怎么办呢,能够用js的方法拼接好在submitphp

<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.htmlhtml

这种方法在每次提交的时候,会一直拼接uri,在个人项目上用不了,不过给了我启发,那就是js中重定向,代码以下:web

<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>
相关文章
相关标签/搜索