扫码关注官方订阅号
点击一个超链接,怎么获取到它的url呢?
学习是最好的投资!
[].forEach.call(document.querySelectorAll('a'),function(o){ o.onclick = function(){ var s = this.href; console.log(s); return !1; }; });
获取属性啊,用attr
$(document).on('click','a',function(){console.log($(this).attr('href'))})
var link = document.getElementById('linkId'); // 针对你点击的链接进行修改 link.href; // 或 link.getAttribute('href');
$('#linkId').attr('href')
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
获取属性啊,用attr
$(document).on('click','a',function(){console.log($(this).attr('href'))})
js
jquery