将查询字符串添加到当前URL中嵌入的查询的锚链接

Add a query string to anchor link from query embedded in current URL

本文关键字:查询 链接 添加 字符串 URL      更新时间:2023-09-26

如何将"?q='query'"(其中'query'是搜索框中的查询字符串,嵌入当前页面的URL示例.com/search/?='query')动态添加到页面上的锚链接?

这方面的一个例子可以在网站上找到:https://www.ecosia.org/search?q=test

在这里,页面包含带有"?"的链接?q=添加到它们的测试查询(例如。https://www.ecosia.org/images?q=test)

感谢您的帮助

这将把页面URL中的查询字符串附加到页面上的每个链接上。

var qs =window.location.search; 
$('a').each(function(){
    var href = $(this).attr('href')
    $(this).attr('href',href+qs)
})