首页 > 解决方案 > jQuery 将文本添加到 URL 的末尾

问题描述

我有这个代码:

$('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';
});

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

标签: jqueryurlhref

解决方案


尝试改变

this.href + '#respond';

对此

this.href += '#respond';


推荐阅读