在php函数中包含自定义js文件
我有一个自定义函数,可以根据查看的de页面包含自定义javascript文件。 这就是功能:在php函数中包含自定义js文件,php,javascript,jquery,html,Php,Javascript,Jquery,Html,我有一个自定义函数,可以根据查看的de页面包含自定义javascript文件。 这就是功能: function custom_jsinclude($php,$jsfile) { // $filename = basename($_SERVER['PHP_SELF']); if($filename === $php) { echo "<script src=\"js/$jsfile\"></script>\n"; } else { exit("Couldnt f
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");
}
}
你试过这个吗:
echo '<script type="text/javascript" src="js/'.$jsfile.'"></script>\n';
乍一看,您缺少了一个“s”,您可以提供更多的代码吗?当您从浏览器检查源代码时,您应该访问从PHP脚本生成的URL,以检查断开的链接。它没有断开,我可以访问它。@rlemon您想看什么代码?
<!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>
$(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();
}
});
});
echo '<script type="text/javascript" src="js/'.$jsfile.'"></script>\n';