如何使用jQuery将查询字符串参数附加到超链接URL
我有一个完整的jQuery代码来选择与指定域匹配的URL:如何使用jQuery将查询字符串参数附加到超链接URL,jquery,Jquery,我有一个完整的jQuery代码来选择与指定域匹配的URL: jQuery( document ).ready( function( $ ) { $('a').each(function() { var href = $(this).attr('href'); if(this.hostname && this.hostname == 'example.com') {
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)
}
});
});
如您所见,它将删除target属性,添加rel nofollow并将title设置为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插件的简单方法可以做到这一点?查看对象和数组
或用于表单数据
示例:在脚本中添加nofollow并不能真正满足您的需要。Google等运行了一些JS,但不多,您的nofollow可能不会受到尊重。最好是在服务器端完成这项工作。谢谢Clint,好的,我明白了。但是,您知道如何将查询字符串参数添加到选定的超链接URL吗?