gpt4 book ai didi

javascript - 如何使用jquery链接到表中的特定 anchor

转载 作者:行者123 更新时间:2023-11-30 23:47:00 26 4
gpt4 key购买 nike

我正在使用这个 jquery 插件:

http://www.jankoatwarpspeed.com/post/2009/07/20/Expand-table-rows-with-jQuery-jExpand-plugin.aspx

我在代码中有 anchor ,例如:

<a name="art" id="art2"></a> Articles

那么我怎样才能打开该特定行呢?换句话说,当用户单击从另一个页面到此登录页面的链接时,我希望根据 anchor 标记打开相应的行。

提前致谢!

最佳答案

在 document.ready 中,您可以调用该 anchor 的单击事件,如下所示:

$(function() {
if(document.location.hash != '')
$(document.location.hash).click();
});

例如,这将使www.yoursite.com/yourPage.htm#art2执行对该链接的点击,从而将其打开。只需确保上面的代码位于您的点击事件处理程序之后,这样它实际上会在点击时执行一些操作:)

如果您使用指定 anchor 登陆#art,请使用类似的方法:

$(function() {
if(document.location.hash != '')
$('a[name="' + document.location.hash.replace('#','') + '"]').click();
});

关于javascript - 如何使用jquery链接到表中的特定 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2740377/

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