gpt4 book ai didi

javascript - 触发点击带有标签的 URL

转载 作者:行者123 更新时间:2023-11-29 18:30:33 25 4
gpt4 key购买 nike

你能触发点击带有 hashtag 的 URL 吗?

例如:

我有这个链接:<a class="contact">Contact Me</a>

当我访问 www.example.com/#contact 时开火:$('a.contact').trigger('click');

这有可能通过任何 hacky 方式实现吗?

最佳答案

var hash = window.location.hash.slice(1); // get the hash, and strip out the "#"

if( hash /* && hash === 'contact' */ ) // if there was a hash
$('a.' + hash ).trigger('click'); // concatenate it into the selector

关于javascript - 触发点击带有标签的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8887209/

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