您可以触发带有主题标签的 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/