dty98339 2014-09-20 14:42
浏览 40

jQuery不能在PHP中工作

I got a little problem with jQuery here.

Basically, I include my pages in the index.php page. However, SOME jQuery is not working, while others are okay. All scripts used in all pages are loaded in the tag of index.php.

      <head>
      <meta charset="utf-8">
      <title>Shy Shop</title>
      <!--js-->
      <script type="text/javascript" src="js/jquery-1.8.2.js"></script>
      <script type="text/javascript" src="js/common.js"></script>
      <script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
      <script type="text/javascript" src="js/ddsmoothmenu.js"></script>
      <script type="text/javascript" src="js/jquery.flexslider.js"></script>
      <script type="text/javascript" src="js/jquery.elastislide.js"></script>
      <script type="text/javascript" src="js/jquery.jcarousel.min.js"></script>
      <script type="text/javascript" src="js/jquery.accordion.js"></script>
      <script type="text/javascript" src="js/light_box.js"></script>
      <script type="text/javascript" src="js/search.js"></script>
      <script type="text/javascript">
      jQuery(document).ready(function(){jQuery(".inline").colorbox({inline:true, width:"50%"});});
      </script>
      <!--end js-->

      <!-- Mobile Specific Metas ================================================== -->
      <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

      <!-- CSS ================================================== -->
      <link rel="shortcut icon" href="Images/icons/favicon.png">
      <link rel="stylesheet" href="css/style.css">
      <link rel="stylesheet" href="css/colors.css">
      <link rel="stylesheet" href="css/skeleton.css">
      <link rel="stylesheet" href="css/layout.css">
      <link rel="stylesheet" href="css/ddsmoothmenu.css"/>
      <link rel="stylesheet" href="css/elastislide.css"/>
      <link rel="stylesheet" href="css/home_flexslider.css"/>

      <link rel="stylesheet" href="css/light_box.css"/>
      <link href="../../../html5shiv.googlecode.com/svn/trunk/html5.js">

      <!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->

      <!--[if lt IE 9]>
                  <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
              <![endif]-->

      </head>

And this is how I include the rest of the files in index.php.

          <?php
          if(!isset($_REQUEST['pg']))
          {
              $pg = "home";
          }
          else
              $pg = $_REQUEST['pg'];
          if($pg=="shopguide")
              include("faqs.php");
          elseif($pg=="aboutus")
              include("aboutus.php");
          elseif($pg=="contactus")
              include("contactus.php");
          elseif($pg=="home")
              include("home.php");
          elseif($pg=="shop")
              include("shop.php");
          elseif($pg=="sitemap")
              include("sitemap.php");
          elseif($pg=="product")
              include("product.php");
          elseif($pg=="shoppingcart")
              include("shoppingcart.php");
          elseif($pg=="profile")
              include("account.php");
          elseif($pg=="orders")
              include("orders.php");
          elseif($pg=="wishlist")
              include("mywishlist.php");
          elseif($pg=="changepassword")
              include("changepassword.php");
          elseif($pg=="newmessage")
              include("newmessage.php");
          elseif($pg=="receivedmessages")
              include("receivedmessages.php");
          elseif($pg=="ordersummary")
              include("ordersummary.php");
          elseif($pg=="test")
              include("test.php");
          elseif($pg=="viewmessage")
              include("viewmessage.php");
          elseif($pg=="register")
              include("register.php");
          elseif($pg=="login")
              include("login.php");
          elseif($pg=="reseller")
              include("reseller.php");
          elseif($pg=="myaccount")
              include("orders.php");
        ?>

An example of a working js in the included files is the jcarousel.min.js. The accordion.js and light_box.js does not work with the included files, but they work when they are used in a single file.

Console says: Uncaught TypeError: undefined is not a function.

  • 写回答

1条回答 默认 最新

  • duancheng7743 2014-09-20 15:12
    关注

    This issue may happen when you have same plugin/jquery files included in other php files too. e.g. in index.php, you have some JS files, you are including other PHP files which may also have same JS again. In such cases, jQuery behaves like this. To check this, just check the view source of generated html.

    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私