gpt4 book ai didi

javascript - 通过 jQuery 检查链接

转载 作者:行者123 更新时间:2023-11-28 16:33:02 25 4
gpt4 key购买 nike

有一个链接 block ,

<div class="links">
<a href="http://google.com">
<a href="http://bing.com">
<a href="http://example.com/section2/">
</div>

它们都放在http://example.com/的html中。

如何检查每个链接,是否是当前打开网站的链接?

脚本应该为 http://example.com/anything/else/in/the/url/ 提供 true,为所有其他网站提供 false。

最佳答案

在 GitHub 上查看我的 jQuery 插件 $.urlParser:https://github.com/Dyvor/jquery/tree/master/plugins/urlParser

您可以尝试以下代码:

var current_host = $.urlParser(window.location.toString()).host;
$('div.links a').each(function() {
if ( current_host == $.urlParser($(this).attr('href')).host ) {
// the hosts matched ... place your code here
}
});

关于javascript - 通过 jQuery 检查链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5170582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com