在php中包含bootstrap和js [英] Including bootstrap and js in php

查看:70
本文介绍了在php中包含bootstrap和js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一双新眼睛才能看到这个!

I need a fresh pair of eyes to look at this!

我直接从我的一个老式小提琴中取代码 https://jsfiddle.net/RachGal/fs9u6mwe/1/ 在大学厨房网站上显示照片。但它只显示一个。当我在我的PHP中包含bootstrap和函数时,它似乎没有读取它!为什么会这样?

I took code directly from one of of my old fiddles https://jsfiddle.net/RachGal/fs9u6mwe/1/ to display photos in a college galley site. However it only shows one. When i include bootstrap and the function in my php it doesn't seem to read it! Why could this be?

我的php看起来像这样

My php looks like this

<?php
echo "<html><head><meta charset='utf-8'>";
echo "<script type='text/javascript' src='scripts/bootstrap.js'></script>";
echo"<link rel='stylesheet' type='text/css' href='css/style.css'>";
include "scripts/show.php";
echo" <title>Gallery Display</title></head><body>";

echo "<header>";
echo "<h1>The Ultimate Gallery Compiler</h1>";
echo "<div id='menu'><a class='head' href='index.html'>Upload Photo</a>&nbsp;&nbsp;<a class='head' href='gallery.html'>Browse Gallery</a></div>";
echo "</header>";
echo "<div id='content'>";
echo "<h2>Browse Gallery</h2>";
$subfolder = $_POST["category"];
if ($subfolder == "0"){
    echo("Please <a href='gallery.html'>go back</a> and select a category");
    echo "</div><br><br>";
    echo "<footer>";
    echo "<p class='foot'>&copy; Copyright 2015-2016 MMA2 Rachel Gallen, Ysabel Pheifer and Rebecca Merrigan.</p>"; 
    echo "</footer>";
    exit();
}
$countcontents = file_get_contents("categories.txt"); //read file to get count
$countarray = explode('*', $countcontents); //get count of each category into an array
$categories = array("fashion", "music", "sports", "technology", "animals", "health", "other");


//output title according to if the gallery has images in it or not
for($i=0; $i< count($countarray); $i++)
{
    if ($subfolder == $categories[$i]){
        if (intval($countarray[$i]) == 0) {
             echo "<h3>No images have been uploaded for the " .$subfolder. " category yet</h3>";
        }
        else
        {
            echo "<h3>Here are the images for the " .$subfolder. " category</h3>"; 
            echo "<p>There are ".$countarray[$i]." photos in this category</p><br>";
        }
    }
}

$folder = "images/".$subfolder."/";

// Open the appropriate subfolder, and display its contents.
// http://php.net/manual/en/function.opendir.php
// also referenced https://www.youtube.com/watch?v=nGLi4ykt__0
if ($dir = opendir($folder)) {
    $images = array();
    while (false !== ($file = readdir($dir))) {
        if ($file != "." && $file != "..") {
            $images[] = $file; 
        }
    }
    closedir($dir);
}

echo '<div id="slider">';
echo "<ul id='slides'>";
foreach($images as $image) {
    echo '<li class="slide"><img src="';
    echo $folder.$image;
    echo '" alt=""/></img></li>';
}
echo "</ul>";
echo '</div>';
echo "<p>&nbsp</p><a href='gallery.html'>Reselect</a>";

echo "</div>";
echo "<footer>
<p class='foot'>&copy; Copyright 2015-2016 MMA2 Rachel Gallen, Ysabel Pheifer and Rebecca Merrigan.</p> 
</footer>";
echo "</body></html>";
?>

任何帮助都将不胜感激!

Any help would be appreciated!

顺便说一下javascript是

by the way the javascript is

//Reference https://jsfiddle.net/RachGal/fs9u6mwe/1/

$(document).ready(function() {

  //INDEX IMAGES SLIDER
  $(function slider() {

    //configuration
    var width = 360;
    var speed = 1000;
    var pause = 3000;
    var current = 1;


    //cache DOM
    var $slider = $('#slider');
    var $slides = $slider.find('#slides');
    var $slide = $slides.find('.slide');


    setInterval(function() {
      //move image the defined width and speed to the left
      $slides.animate({
        'margin-left': '-=' + width
      }, speed, function() {
        //count number of slides and loop back to first from last
        current++;
        if (current === $slide.length) {
          current = 1;

          $slides.css('margin-left', 0);
        }
      });
    }, pause);
  });
}

);


推荐答案

你没有在你的页面中包含jQuery,你是在你的脚本中使用jQuery但它根本没有加载。

You have not included jQuery in your pages, you are using jQuery in your script but it is not loaded at all.

找到这些东西的好方法是在使用chrome时按F12使用开发者栏,然后在网络,你可以看到哪些文件被加载,如果有任何javascript错误,你可以在控制台中。

A nice way to find these things out is using the developer bar by pressing F12 when using chrome, then at network you can see which files were loaded and in console if there were any javascript errors.

这篇关于在php中包含bootstrap和js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆