gpt4 book ai didi

jquery - 如何使用 jQuery 将查询字符串参数附加到超链接 URL

转载 作者:行者123 更新时间:2023-12-01 01:25:42 25 4
gpt4 key购买 nike

我有一个完全有效的 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)
}
});
});

如您所见,它将删除 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 插件的情况下完成此操作?

最佳答案

查看jQuery.param()对于对象和数组

.serialize()对于表单数据

示例:http://jsfiddle.net/DqXYn/

关于jquery - 如何使用 jQuery 将查询字符串参数附加到超链接 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14450922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com