扫码关注官方订阅号
麻烦把提取的完整href值赋给的变量注释一下
小伙看你根骨奇佳,潜力无限,来学PHP伐。
(function () { var a = document.getElementsByTagName('a'); for (var i = 0; i < a.length; a++) { a[i].onclick = onclick; } function onclick() { var href = this.href; if (href) { //TODO return true; } else { //TODO return false; } } })();
[].forEach.call(document.querySelectorAll('a'), function(a) { return console.log(a.hostname); });
// ES6 Array.from(document.querySelectorAll('a')).forEach( (item) => console.log(item.host) );
// ES5 [].slice.call(document.querySelectorAll('a')).forEach(function(item){ console.log(item.host); });
有个jquery的url插件用起来很方便
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
有个jquery的url插件用起来很方便