0
我有一個定製功能,包括自定義JavaScript文件瀏覽取決於德頁面上。 這是函數:包括自定義js文件與PHP函數
function custom_jsinclude($php,$jsfile) { //
$filename = basename($_SERVER['PHP_SELF']);
if($filename === $php) {
echo "<script src=\"js/$jsfile\"></script>\n";
} else {
exit("Couldnt find file");
}
}
早在我的PHP文件包括我像這樣(head標籤之間)。
<?php
require_once('inc/functions.php');
custom_jsinclude("somepage.php","custom-scrollTo.js");
?>
當我加載的頁面包括在JavaScript文件(檢查源)。但它不起作用。
然後我試圖舊的方式方法: <script src="js/custom-scrollTo.js"></script>
,並能正常工作......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to my homepage</title>
<script src="js/custom-scrollTo.js"></script>
<script src="js/jquery-1.7.2.min.js"></script>
<link href="css/somepage.css" rel="stylesheet" type="text/css" />
</head>
缺少什麼我在這裏?
的scrollTo代碼:
$(document).ready(function() {
$("#prlmenu li").click(function(){
var indexli = $(this).index();
var indexh3 = indexli;
var scrollto = $('h3:eq('+indexli+')').offset().top;
$("html, body").animate({ scrollTop: scrollto +'px' },"fast");
});
$("div.backtotop").click(function() {
$("html, body").animate({ scrollTop: "130px" },"fast");
});
$(window).scroll(function() {
if($("html, body").scrollTop() > 1510) {
$("div.backtotop").fadeIn("slow");
} else {
$("div.backtotop").hide();
}
});
});
乍一看你錯過了一個 '計劃** S **' – rlemon 2012-04-18 14:28:04
可以爲您提供可能更多的代碼? – rlemon 2012-04-18 14:28:56
當您從瀏覽器檢查源代碼時,您應該訪問您從PHP腳本生成的URL,以檢查是否存在損壞的鏈接。 – vedarthk 2012-04-18 14:37:25