doubianyan9749 2014-05-19 12:09
浏览 18
已采纳

JavaScript无法在PHP文件中工作(滚动时的框阴影)

My problem :

  1. JavaScript is not working at my .php files
  2. My CSS not work while scrolling

*CSS Files named "var.css"

#kepala {
    padding: 10px;
    top: 0px;
    left: 0px;
    right: 0px;
    position: fixed;
    background - color: #EBEBEB;
    height: 35px;
#kepala.scrl {
    box - shadow: 0px 1px 5px rgba(0, 0, 0, 0.3);
}

*PHP Files named "home.php"

<?php
include "koneksi.php";
session_start();

if(isset($_SESSION['username'])) {

if($_SESSION['user'] == "blabla"){
?>

<html>

    <head>
        <link rel='stylesheet' type='text/css' href='var.css'>
    </head>

    <script type="text/JavaScript">
        $(function(){
            $(window).on('scroll', function(){
                if ( ! $(document).scrollTop()) {
                    $('#kepala').removeClass('scrl');
                } else {
                    $('#kepala').addClass('scrl');
                }
            });
        });
    </script>

    <body>
        <div id="kepala">
            Blablabla
        </div>
    </body>
</html>

I just can't understand why my JavaScript doesn't work.
There is no effect when I'm scrolling down the header.

  • 写回答

1条回答 默认 最新

  • douyin2435 2014-05-19 12:11
    关注

    You're using jQuery, but you haven't included it. Add the following line in the head before your script:

    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)