繁体   English   中英

依次调用一个函数以获取正确的网址

[英]Call one function after another to get the proper url

嗨,我在草地上工作..

<g:link name="searchLink" controller="MRController"  
action="ExcelExport">TEST GRAILS</g:link>

<script>
        $(function() {
            $('a[name="searchLink"]').bind('click', function() {
            $(this).attr('href', $(this).attr('href') + '?startdate=' + start().StartDate +'&enddate=' + start().Enddate);
            })
            })


       function start(){

        var StartDate =  $("#startDate").val();
        var Enddate=  $("#endDate").val();
        return {StartDate:StartDate,Enddate:Enddate}
        }
    </script>

我试图获取以下网址

 http://localhost:8077/Myproject/MRController/ExcelExport  
 ?startdate=2017-05-21&enddate=2017-05-23

但是,当我再次单击链接时,我得到以下URL,而我希望链接具有新的开始日期和结束日期值

 http://localhost:8077/Myproject/MRController/ExcelExport?  
 startdate=2017-05-21&enddate=2017-05-23?startdate=2017-05-21&enddate=2017-05-23

编辑

我尝试使用以下脚本在第一次调用中清除参数,但我不知道如何使脚本一个接一个地运行,这意味着首先执行url调用,然后通过函数清除参数

<script>
function refineUrl()
        {   
        //get full url
        var url = window.location.href;
        //get url after/  
        var value = url.substring(url.lastIndexOf('/') + 1);
        //get the part after before ?
        value  = value.split("?")[0];
        return value; 
        }

    </script>

不要在您的JS代码中更改原始href属性:

$('a[name="searchLink"]').bind('click', function() {
    document.location = $(this).attr('href') + '?startdate=' + start().StartDate +'&enddate=' + start().Enddate;            
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM