Jquery:将查询字符串附加到所有链接 [英] Jquery : Append querystring to all links

查看:15
本文介绍了Jquery:将查询字符串附加到所有链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在页面内的所有动态链接上附加一个查询字符串 - 修复旧版本中的错误 - 这可能吗?

I would like to append a query string onto all dynamic links within a page - to fix a bug in a old release - is this possible?

有什么想法吗?

推荐答案

类似的事情?

var querystring = 'myquerystringtoadd';

$('a').each(function() {
    var href = $(this).attr('href');

    if (href) {
        href += (href.match(/?/) ? '&' : '?') + querystring;
        $(this).attr('href', href);
    }
});

工作示例.

这篇关于Jquery:将查询字符串附加到所有链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆