1. 程式人生 > >form表單提交時,action怎麼帶引數

form表單提交時,action怎麼帶引數

在提交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>

這種方法在每次提交的時候,會一直拼接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>