在当地工作,所以我不能给你任何链接,但我会尝试解释这种情况.
我正在做一个wordpress网站,我正在创建ajax请求,使网站上的任何内部链接都会加载到主页面的主要内容区域.
这是我正在使用的整个脚本
jQuery(document).ready(function($) { //individua il container in cui sarà caricata la pagina var $mainContent = $("#main-wrapper"), //individua l'url "madre" siteUrl = "http://" + top.location.host.toString(), url = ''; $(document).on("a[href^='"+siteUrl+"']:not([href*=/wp-admin/]):not([href*=/wp-login.php]):not([href$=/feed/])", "click", function(event) { location.hash = this.pathname; if ( event.preventDefault ) { event.preventDefault(); } else { event.returnValue = false; } }); $(window).bind('hashchange', function(){ url = window.location.hash.substring(1); if (!url) { return; } url = url + " #content"; $mainContent.animate({opacity: "0.1"}).html('<p>Please wait...</>').load(url, function() { $mainContent.animate({opacity: "1"}); }); }); $(window).trigger('hashchange'); })
简而言之,你可以看到我是如何"禁用"链接的:我想避免加载到外部页面的链接
我在控制台中收到的错误是这样的:
不推荐使用event.returnValue.请改用标准的event.preventDefault().
我该如何解决?
我相信事件类型应首先出现在on
绑定中,然后是选择器:
$(document).on("click", "a[...])", function(event) ...