我找到了一个关于我的问题的话题,但没有答案..
我有一个带有ajax导航的网站,它与主要导航工作完美,但没有实习链接。实际上,当进行Ajax调用的链接在要更改的内容中时,它会出现错误(它适用于第一次单击,但如果在加载内容时单击另一个实习链接则不起作用)。在这种情况下,页面将重新加载...
http://miller-badger-76351.netlify.com/
你可以在链接上测试它,实习链接是主页上的“Découvrenotreagence”和Agence页面上的“Découvreznotreoffre”(这是一个法国网站)。
$('a[class^="link"]').on('click', function(event){
event.preventDefault();
_href = $(this).attr("href");
history.pushState(null, null, _href);
$('.content-yield').load('..' + _href + ' .contain', function(){
window.scrollTo(0,0)
}); // _href is the name of the html doc, for example, for the Agence page, the load string will be '../l'agence/ .contain'
我希望我的问题很清楚,我事先感谢你们所有人的帮助=)
度过愉快的一天
答案 0 :(得分:0)
最后找到了解决这个问题的方法:
$('body').on('click', 'a[class^="link"]', function(event){
event.preventDefault();
_href = $(this).attr("href");
history.pushState(null, null, _href);
$('.content-yield').load('..' + _href + ' .contain', function(){
window.scrollTo(0,0)
});
您只需选择所有身体并将选择器添加为参数!