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>

 

原文連接: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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM