hello

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>
复制代码

 

posted @   红尘练  阅读(26904)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
你来了
点击右上角即可分享
微信分享提示