更多的项目链接可以更改为具有A HREF它可以说:
<a href="#more-1" class="next">More Projects</a>
这时旁边的onClick你可以做这样的事情在jQuery的:
jQuery(function ($) {
if(window.location.hash) {
// onLoad hash was detected
console.log('onLoad hash detected // do something to position menu');
// window.location.hash starts with a # following with the string behind it
// window.location.hash.slice(1) gets the string only
}
// This isn't needed but quessing you already have an onClick set up for this element...
$('a.next').click(function (e) {
/*
Don't do e.preventDefault()! The browser will add the href hash value itself if you only specified the hash!
If you want to preventit you will have to set the hash yourself like this:
window.location.hash = 'more-1';
*/
// do stuff, possibly with the href value since you have it anyway
// I reccommend that you change the value of the href to specify the next hash value change
$(this).attr('href', '#more-2');
});
});
更新问题:jQuery haschange可以用于这样的事情吗?点击更多项目时,我不会更改网址。 Cookie是解决此问题的唯一方法吗? – saltcod 2012-03-17 15:09:51
您可以使用cookies,但我不确定这是否会增加复杂性。这是如何:http://www.w3schools.com/js/js_cookies.asp – 2012-03-17 15:45:51