【发布时间】:2019-08-20 06:54:18
【问题描述】:
我尝试更改 jQuery 代码。我需要将代码行更改为某些内容,即选择所有包含我的网站网址的href链接,而不是链接中的“访问”一词。
以下代码是插件中的标准代码,我想更改它。
让我们看看网址。
jQuery select all a href 因为我的网站 url 在示例内部,但我有外部链接,不应选择。
外部链接https://www.example.com/visit/1234
我试过(添加 :not.a[href*="visit] 到 https 行
jQuery('a[href^="http://'+document.domain+'"],a[href^="https://'+document.domain+'"]:not.a[href*="visit],a[href^="/"],a[href^="?"]').each(function()
完整代码(123 代替插件名称)
<?php if (isset($_GET['123_123'])) { ?>
function 123_add_link() {
jQuery('a[href^="http://'+document.domain+'"],a[href^="https://'+document.domain+'"],a[href^="/"],a[href^="?"]').each(function() {
this.href += (/\?/.test(this.href) ? '&' : '?') + '123=true&123_123=true';
});
}
jQuery( document ).ajaxComplete(123_add_link());
jQuery(document).ready(123_add_link());
<?php } ?>
【问题讨论】:
标签: jquery