jQuery-网址位置和点击事件 [英] JQuery - url location and click event
本文介绍了jQuery-网址位置和点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$('#head_menu a').click(function(){ currentPage = document.location.hash.split('#')[1]; });
$('#head_menu a').click(function(){ currentPage = document.location.hash.split('#')[1]; });
<div id="head_menu">
<a href="#order"><div>make order</div></a>
<a href="#portfolio"><div>portfolie</div></a>
<a href="#contacts"><div>contacts</div></a>
<a href="#vacancies"><div>vacancies</div></a>
<a href="#about"><div>about company</div></a>
</div>
因此,当我单击head_menu div中的链接时,我进入了此处理程序.但有一个麻烦:例如,如果url中包含#about哈希,则在单击处理程序时,我会得到"about",而不是"about".我可以在点击处理程序中获取新的url哈希吗?
So, when I'm clicking to the links in head_menu div I come into this handler. But one trouble: if url has, for example, #about hash, in handler I'll get 'about', not that, at what I've clicked. Could I get new url-hash in click-handler?
推荐答案
为什么不只查看被单击链接的href
属性?
Why not just look at the href
attribute of the link that was clicked?
$('#head_menu a').click(function(){
currentPage = this.href.split('#')[1];
});
这篇关于jQuery-网址位置和点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文