【问题标题】:Add a query string to anchor link from query embedded in current URL将查询字符串添加到来自当前 URL 中嵌入的查询的锚链接
【发布时间】:2016-08-12 02:47:12
【问题描述】:

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

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

此处的页面包含添加了“?q=test”查询的链接(例如https://www.ecosia.org/images?q=test

感谢您的帮助

【问题讨论】:

    标签: javascript wordpress hyperlink anchor query-string


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2017-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-20
      • 2011-09-21
      • 2012-04-26
      • 2021-06-28
      • 2010-12-03
      相关资源
      最近更新 更多