簡體   English   中英

我如何從jQuery腳本中的URL中刪除參數

[英]How can i remove the params from the url in jquery script

我如何從通過以下腳本創建的鏈接中刪除參數...這包括使用jquery,如果可能,請告訴我jquery腳本中的解決方案

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

這是您問題的解決方案。

您具有創建網址的此功能

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

因此,僅為此目的獲取基本URL,就可以在我使用示例URL的地方使用此簡單代碼。 你可能會有所不同

 $( document ).ready(function() { var baseurl = $('.link').attr('href').split('?')[0]; console.log(baseurl); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a class="link" href="https://support.google.com/mail/answer/56256?hl=en&test=213213321312">Normal Sample URL</a> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM