扫码关注官方订阅号
在项目中要求实现这样的要求,我设想使用jquery获取DOM对象,然后遍历对象,逐个在href属性中追加字符串?key=value,但是代码总是报错,虽然有思路,但是写不出来!...
jquery
DOM
href
?key=value
学习是最好的投资!
var qs = 'key=value'; $('a').each(function(){ var href = $(this).attr('href'); if(href) { href += (href.match(/\?/) ? '&' : '?') + qs; $(this).attr('href', href); } });
参考 Over Stackflow
$('a').attr('href',function(i, attr) { return attr + '?key=value'; });
介样
http://stackoverflow.com/questions/11526102/jquery-append-querystring-to-all-links
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
参考 Over Stackflow
介样
http://stackoverflow.com/questions/11526102/jquery-append-querystring-to-all-links