【问题标题】:jQuery add text to end of a URLjQuery 将文本添加到 URL 的末尾
【发布时间】:2021-10-21 03:14:36
【问题描述】:

我有这个代码:

$('a.comment-reply-link').each(function(){
    this.href = this.href.replace("dummy_comment", "author");
    this.href = this.href.replace("#comment-", "?replytocom=");
});

这是有效的,但现在我想在 url #respond 的末尾。所以我把代码写成:

$('a.comment-reply-link').each(function(){
    this.href = this.href.replace("dummy_comment", "author");
    this.href = this.href.replace("#comment-", "?replytocom=");
    
    this.href + '#respond';
});

但这不起作用?我怎样才能让它工作?

【问题讨论】:

  • 试试 this.href += '#respond';

标签: jquery url href


【解决方案1】:

尝试改变

this.href + '#respond';

到这里

this.href += '#respond';

【讨论】:

  • 现在当您单击链接时,页面刷新 url 更改为:example.net/author/?replytocom=4212。但是回复链接随后更改为 example.net/author/?replytocom=4212?replytocom=4212 我该如何避免这种情况?
猜你喜欢
  • 2012-08-03
  • 1970-01-01
  • 1970-01-01
  • 2011-01-05
  • 2013-08-07
  • 1970-01-01
  • 1970-01-01
  • 2016-08-04
  • 1970-01-01
相关资源
最近更新 更多