[英]jQuery Dynamic Page Loading wont work, not sure why any ideas?
Live demo here <- http://webcallonline.exoflux.co.uk/html/ 此处的实时演示<-http: //webcallonline.exoflux.co.uk/html/
$(function() {
var url = $(this).attr("href");
$("nav").delegate("a", "click", function(event) {
event.preventDefault();
window.location.hash = $(this).attr('href');
$("#main").slideUp('slow', function(){
$("#main").load(url + " #main", function()
{
$("#main").slideDown('slow');
});
});
});
$(window).bind('hashchange', function(){
newHash = window.location.hash.substring(1);
});
$(window).trigger('hashchange');
});
Does anyone have any ideas? 有人有什么想法吗?
This line: 这行:
var url = $(this).attr("href");
should be moved inside the click handler: 应该在点击处理程序内移动:
$("nav").delegate("a", "click", function(event) {
var url = $(this).attr("href");
event.preventDefault();
since you're loading content based on the href of the clicked anchor. 因为您要基于单击的锚的href加载内容。
EDIT: or do you intend to get the current url? 编辑:还是您打算获取当前的URL?
var url = window.location.href;
? ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.