Tag: external js

JavaScript无法处理外部文件

当我在HTML文档中使用此代码时,它正在工作: $(‘a.tocenter[href*=#]’).click( function() { if (location.pathname.replace(/^\//,”) == this.pathname.replace(/^\//,”) && location.hostname == this.hostname) { var $target = $(this.hash); $target = $target.length && $target || $(‘[name=’ + this.hash.slice(1) +’]’); if ($target.length) { var targetOffset = $target.offset().top; $(‘html,body’).animate({ scrollTop: targetOffset – ( $(window).height() – $target.outerHeight(true) ) / 2 }, 1000); return false;} } }); 如果我尝试将此代码放在外部JavaScript文件中,然后将其链接到: 它不起作用,让它工作我必须把它包装进去: $( window […]