我有一个完全可用的jQuery代码来选择与指定域名匹配的URL:
jQuery( document ).ready( function( $ ) {
$('a').each(function() {
var href = $(this).attr('href');
if(this.hostname && this.hostname == 'example.com')
{
$(this)
.removeAttr('target')
.attr('rel', 'nofollow')
.attr('title', href)
}
});
});
正如您所看到的,它将删除目标属性,添加rel nofollow并将标题设置为URL值。现在我遇到了一个问题,如何修改上面的代码以添加另一个功能来将查询字符串附加到URL值(href值)。假设我想附加以下查询字符串参数/值:
argument1='test1'
argument2='test2'
最终的URL将会是这样:
http://example.com/?argument1=test1&argument2=test2
或者是示例域名的任何页面,例如:
http://example.com/any_page/?argument1=test1&argument2=test2
有没有一种不使用jQuery插件的简单方法来完成这个操作?