jQuery动态加载内容
我在动态加载内容时遇到问题。我有一个菜单,在 div 单击隐藏后,他们正在加载新内容并且他正在移动..它工作正常,但是在新内容中我有子菜单,它希望对菜单使用相同的效果,但是是出现问题和链接导致立即通过
也许它更容易理解:):我有 CONTNET DIV,它是动态加载如果我单击菜单中的链接...新内容正在正确加载。在新内容中,我有子菜单,但如果我单击链接,所有网站都会重新加载...如果我只想加载“内容 div”,我该怎么办...
代码中有什么问题?
$(document).ready(function() {
var hash = window.location.hash.substr(1);
var href = $('.nav li a').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-5)){
var toLoad = hash+'.html #content';
$('#content').load(toLoad)
}
});
$('.nav li a').click(function(){
var toLoad = $(this).attr('href')+' #content';
$('#content').hide('fast',loadContent);
$('#load').remove();
$('#wrapper').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('#content').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#content').show('normal',hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
});
我尝试使用你的建议,但它没有效果..
我做了示例页面..
你可以看到,如果你点击菜单,一切都可以,但是如果你要点击“欢迎内容”中的子菜单,所有网站都会重新加载,但如果你再次点击,则只加载 Content Div ..
有人有想法吗?
I have a problem with dynamic loading contents. I have the menu where after div clicking is hiding, they are loading new contents and he is moving.. it works correctly, however in new contents I have submenu, which would like to use the same effect for what for the menu, however is coming into existence the problem and the link cause the immediate passage
Maybe it's more understandable:) : I have CONTNET DIV, which is dynamic loading If I click link in MENU... The new content is loading correctly. In new content I have submenu but if I click links there all site is reloaded... What I can do if I want loading only 'content div'..
What's is wrong in code ?
$(document).ready(function() {
var hash = window.location.hash.substr(1);
var href = $('.nav li a').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-5)){
var toLoad = hash+'.html #content';
$('#content').load(toLoad)
}
});
$('.nav li a').click(function(){
var toLoad = $(this).attr('href')+' #content';
$('#content').hide('fast',loadContent);
$('#load').remove();
$('#wrapper').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('#content').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#content').show('normal',hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
});
I tried to use your advice , but it doesn't effect..
I did example page..
You can see, if you click on menu, all it's ok, but if you are going to click submenu in 'welcome content' all site are reloaded, but if you click again, only Content Div is loaded..
anybody has an idea ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我对你的查询的理解,这可能会做到。
From what I could understand of your query, this might do it.
您的母语是什么?我认为在其中回答会更容易。
对吗?您单击主菜单中的任何项目并使用 AJAX 加载到页面新菜单,但新菜单中的项目不会调用 AJAX 请求?
如果是这样,您需要根据需要将 AJAX 函数调用应用于新菜单、其项目或空洞加载的内容。
我认为你的代码太复杂了,需要一些改进。
What is your native language? I think it would be easier to answer in it.
Is it right? You click in main menu any item and load to the page new menu using AJAX, but items in new menu doesn't call AJAX request?
If it is so, you need to apply the AJAX function call to the new menu, its items or the hole loaded content, as you like.
I think your code is too complicated at all, it needs some improvements.