在通过ajax加载内容时,我使用jquery.address插件来更新浏览器的地址栏。一切正常,除了我不知道如何自动加载event.value或event.path到DIV中,当用户试图访问一个像"domain.com/about-us“这样的书签页面时,我用来加载内容,在这种情况下,页面会加载,但"about-us”内容不会加载到DIV中。我遗漏了什么?这是我的代码:
JS:
function loadURL(url) {
$("#content").fadeOut(600, function() {
$(this).load(url).fadeIn(800);
});
}
$.address.init(function(event) {
$.ajax({
url: event.value,
success: function(data){ $('#content').load(data); }
});
}).change(function(event) {
$('a').click(function(){
loadURL($(this).attr('href'));
});
});HTML:
<div id="menu">
<ul>
<li id="menu_about"><a href="about-us.html" rel="address:/about-us">About Us</a></li>
<li id="menu_contact"><a href="contact.html" rel="address:/contact">Contact</a></li>
</ul>
</div>
<div class="wrapper">
<div id="content">
</div>
</div>.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
# Rewrite current-style URLs of the form 'index.html?url=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html?url=$1 [L,QSA]
</IfModule>谢谢!
发布于 2013-09-12 19:25:00
$.address.externalChange(function(event))就是你要找的东西。它将捕获页面加载时的路径。
https://stackoverflow.com/questions/16879739
复制相似问题