[英]Get Hash URL from anchor and load into Div
I have a video gallery that has a menu on the left and loads the content into a div on the right hand side. 我有一个视频库,该视频库的左侧有一个菜单,并将内容加载到右侧的div中。 The menu is generated from php video posts so we need a general script that will effect everything.
菜单是从php视频帖子中生成的,因此我们需要一个可以影响所有内容的通用脚本。
-- The problem -- - 问题 -
The links will load the URL of the video as an anchor on the current URL - 这些链接会将视频的网址加载为当前网址的锚点-
eg. 例如。
http://www.divethegap.com/update/community/videos/#http://www.divethegap.com/update/2010/10/test-video-2/ http://www.divethegap.com/update/community/videos/#http://www.divethegap.com/update/2010/10/test-video-2/
So all I need is a script that will get the hash tag and load the content into a div. 因此,我只需要一个脚本,该脚本将获取哈希标签并将内容加载到div中。 So far I have failed miserably trying to do that.
到目前为止,我惨遭失败,未能做到这一点。 I imagine it is something along the lines of document.location.hash but don't know where to go from there.
我想象这是document.location.hash的一部分,但不知道从那里去。
Help much appreciated. 帮助非常感谢。
Thanks 谢谢
Note: this answer users jQuery because 1.4.2 is included and being used extensively in the page already. 注意:此答案使用jQuery,因为1.4.2已包含并已在页面中广泛使用。
You can attach a click handler to the anchors, for example: 您可以将点击处理程序附加到锚点,例如:
$("#nav a").click(function() {
$("#content").load(this.hash.substring(1));
});
You can test it out against your markup here , not it won't actually load in the demo since it's on a separate domain, but will work fine on the same domain. 您可以在此处针对您的标记进行测试,因为它位于单独的域中,因此它不会实际上不会加载到演示中,但可以在同一域中正常工作。
You can try this - 你可以试试这个-
$('a').click(function(){
$('#content').load(document.location.hash.replace(/#/,''));
});
This will load the content after hash part from the current url. 这将从当前URL的哈希部分之后加载内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.