触发器使用#标签点击URL [英] Trigger click on URL with hashtag

查看:104
本文介绍了触发器使用#标签点击URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能用点标签触发点击网址吗?

Can you trigger click on URL with hashtag?

例如:

我有这个链接: < a class =contact>与我联系< / a>

当我访问 www.example.com/#contact 开火: $('a.contact')。触发器('click');

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

Is this possible by any hacky way?

推荐答案

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

这篇关于触发器使用#标签点击URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆