Javascript 在提交表单之前修改查询字符串

Javascript 在提交表单之前修改查询字符串,javascript,jquery,Javascript,Jquery,我想在提交表单之前修改URL查询字符串。我的表格如下: <form name="sampleForm" id="sampleForm" method="get" action="/detailVal" style="display:inline"> <input type="hidden" name="cId" value="${lId}"/> <input type="hidden" name="sId" valu

我想在提交表单之前修改URL查询字符串。我的表格如下:

 <form name="sampleForm" id="sampleForm" method="get" action="/detailVal" style="display:inline">
            <input type="hidden" name="cId" value="${lId}"/>
            <input type="hidden" name="sId" value="${sId}"/>
            <input type="hidden" name="pKey" value="${pKey}"/>

    onclick="return resetPage('sampleForm',)"><img height="40" width="30" src="/img/next123.png"/></a>

    </form>

    <script type="text/javascript">
    function resetPage(formName) {
         var thisForm = doc
       }    
    </script>

onclick=“return resetPage('sampleForm',)”>
函数重置页(formName){
var thisForm=doc
}    
在提交表单之前,我想更改URL,从
/detailVal?cId=1&sId=2&pKey=3

要想
/detailVal/cId/1/sId=2/pKey/
,您可以尝试函数。

url的构建似乎没有任何逻辑,因此您可能正试图传递包含从元素插入的值的字符串,然后阻止表单提交并重定向到该url:

<script type="text/javascript">
    function resetPage(formName) {
         var thisForm = doc
       }    

    $(function() {
        $('#sampleForm').on('submit', function(e) {
            e.preventDefault();
            var cId = $('[name="cId"]').val(),
                sId = $('[name="sId"]').val();

            window.location.href = '/detailval/cid/'+cid+'/sid='+sId+'/pKey/';
        });
    });
</script>

函数重置页(formName){
var thisForm=doc
}    
$(函数(){
$('#sampleForm')。关于('submit',函数(e){
e、 预防默认值();
var cId=$('[name=“cId”]')。val(),
sId=$('[name=“sId”]')。val();
window.location.href='/detailval/cid/'+cid+'/sid='+sid+'/pKey/';
});
});

您尝试了什么?onsubmit调用一个函数,在该函数中您可以更改表单元素的action属性。尝试重写submit not worked$(“#sampleForm”)。submit(函数(事件){event.preventDefault();var querystring=rewrite_interval_qstring();//querystring等于”?price=1000002000->正是我想要的!querystring=querystring.replace(/[\&;?=]/g,'/');alert(“querystring”+querystring);window.location.href=querystring;})@Nish:action属性将不会获取查询字符串