如何使用jQuery链接到表中的特定锚点 [英] How to link to specific anchor in table with jquery
问题描述
我正在使用此jquery插件:
I am using this jquery plugin:
http ://www.jankoatwarpspeed.com/post/2009/07/20/Expand-table-rows-with-jQuery-jExpand-plugin.aspx
我在代码中有锚点:
<a name="art" id="art2"></a> Articles
那我怎么打开那个特定的行?换句话说,当用户单击从另一个页面到该登录页面的链接时,我希望根据锚标记打开相应的行.
How can I open that particular row then? In other words, when a user clicks a link from another page to this landing page I would like the appropriate row to open up based on the anchor tag.
提前谢谢!
推荐答案
在您的document.ready中,您可以调用该锚点的click事件,如下所示:
In your document.ready you can call the click event of that anchor, like this:
$(function() {
if(document.location.hash != '')
$(document.location.hash).click();
});
例如,这将使www.yoursite.com/yourPage.htm#art2
在该链接上单击以使其打开.只要确保上面的代码位于click事件处理程序的之后,这样它实际上就可以在click上执行某些操作:)
This would make for example www.yoursite.com/yourPage.htm#art2
perform a click on that link causing it to open. Just make sure the above code is after your click event handler, so it actually does something on click :)
如果您使用命名的锚点在#art
上着陆,则采用类似的方法:
If you're landing on #art
using the named anchor, similar approach:
$(function() {
if(document.location.hash != '')
$('a[name="' + document.location.hash.replace('#','') + '"]').click();
});
这篇关于如何使用jQuery链接到表中的特定锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!