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

标签 javascript jquery url 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/

相关文章:

javascript - Chrome 扩展 : Get Parameter from URL

javascript - 使用 YSlow/Web Developer 扩展计算页面大小

Javascript Alert() 被替换

javascript - promise 未按顺序运行

javascript - 在一页上为 CSS 中的 2 个元素创建事件菜单

javascript - 根据 URL 输入动态更改文本

javascript - 如何将 express.js 服务器部署到 Netlify

jQuery 切换 div 和切换文本

jquery - 如何在叠加层顶部附加居中的进度旋转器?

php -/index.php/seo_path 这样的 URI 有多可靠