【问题标题】:Including bootstrap and js in php在php中包含bootstrap和js
【发布时间】:2016-03-26 07:09:39
【问题描述】:

我需要一双新鲜的眼睛来看看这个!

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

我的 php 是这样的

<?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>";
?>

任何帮助将不胜感激!

顺便说一下javascript

//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);
  });
}

);

【问题讨论】:

  • 这与$subfolder = $_POST["category"]; - Notice: Undefined index: category 有关 - POST 失败并且依赖于表单(?)。应该是 GET 但不确定从哪里填充。

标签: javascript php twitter-bootstrap


【解决方案1】:

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

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

【讨论】:

  • @RachelGallen Bootstrap 使用 jQuery,而您正在页面中使用 jQuery。
  • 如果您还检查控制台日志,它会清楚地显示:未捕获的错误:Bootstrap 的 JavaScript 需要 jQuery
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-08
  • 2017-01-26
  • 2011-03-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多