我希望能够将以下内容附加到 href 的末尾 ?iframe=true&width=70%&height=85% 我还需要插入-6ren">
gpt4 book ai didi

javascript - JQuery-向 anchor 添加属性和参数

转载 作者:行者123 更新时间:2023-11-29 22:39:54 25 4
gpt4 key购买 nike

我有链接

<a>href="http://www.ittesters.com></a>

我希望能够将以下内容附加到 href 的末尾

?iframe=true&width=70%&height=85%

我还需要插入一个属性

rel="prettyPhoto[iframes]

我希望当用户单击未加载页面的链接时发生这种情况。这可能吗?

最佳答案

当然可以。您可以添加一个点击事件处理程序来为您完成:

$('a').click(function(){
$(this).attr('href', $(this).attr('href') + '?iframe=true&width=70%&height=85%' );
$(this).attr('rel', 'prettyPhoto[iframes]');
});

您可以阅读更多关于 attr() 的信息和 click() jQuery 文档中的函数。

关于javascript - JQuery-向 anchor 添加属性和参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3416519/

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