Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我有一个php文件,里面的代码中有一个错误,我可以';我不知道该怎么修?以及在何处添加其余代码_Javascript_Php_Css_Html - Fatal编程技术网

Javascript 我有一个php文件,里面的代码中有一个错误,我可以';我不知道该怎么修?以及在何处添加其余代码

Javascript 我有一个php文件,里面的代码中有一个错误,我可以';我不知道该怎么修?以及在何处添加其余代码,javascript,php,css,html,Javascript,Php,Css,Html,代码是: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <meta http-equiv="Content-Type"

代码是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>    
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>    
  <meta http-equiv="Content-Language" content="en"/>    
  <meta name="viewport" content="width=device-width; height=device-height; initial-scale=1.0"/>   

  <link type="text/css" rel="stylesheet" href="screen.css" media="screen,projection,tv"/>    
  <title>change picture</title>    
</head>

<body>

  <div id="slideCounter"></div>
  <div id="slideShow">
  <?php

  $allowed_types = ['png','jpg','jpeg','gif'];
  $imageDir = 'files/radar-simulation-files';
  /*
    Assumes this .php is being run from the http root on the same
    domain as the desired image files.
  */

  $handle = opendir($imageDir);
  while (($imgPath = readdir($handle)) !== false) if (
    in_array(
        strtolower(pathinfo($imgPath, PATHINFO_EXTENSION)),
        $allowed_types
    ) echo '
    <img src="', $imageDir, '/', $imagePath, '" alt="slide" />';
  closedir($handle);

  ?>
  <!-- #slideShow --></div>

  <script type="text/javascript" src="slideShow.js"></script>
未消除的回波(后)

那么,我应该在哪里添加其余的代码呢?我有一个javascript函数和一个css代码。我应该将它们添加到同一个php文件中吗?如果是,在哪里?在html代码之后?在html代码中

这是java脚本代码:

(function(d) {

    // user defines

    var
        swapHours = 0,
        swapMinutes = 0,
        swapSeconds = 5,
        swapTotal = (swapHours * 60 + swapMinutes) * 60 + swapSeconds,
        loopSlideShow = true;

    // some handy helper functions

    function classExists(e, className) {
        return RegExp('(\\s|^)' + className + '(\\s|$)').test(e.className);
    }

    function classAdd(e, className) {
        if (classExists(e, className) return false;
        e.className += (e.className ? ' ' : '') + className;
        return true;
    }

    function classRemove(e, className) {
        if (!classExists(e, className)) return false;
        e.className = e.className.replace(
            new RegExp('(\\s|^)' + n + '(\\s|$)'), ' '
        ) . replace(/^\s+|\s+$/g,'');
        return true;
    }

    function textReplace(e, newtext) {
        if (d.innerText) e.innerText = newText;
            else e.textContent = newText;
    }

    function nodeFirst(e) {
        e = e.firstChild;
        while (e && e.nodeType != 1) e = e.nextSibling;
        return e;
    }

    function nodeLast(e) {
        e = e.lastChild;
        while (e && e.nodeType != 1) e = e.prevSibling;
        return e;
    }

    function nodeNext(e) {
        while (e) if ((e = e.nextSibling).nodeType == 1) return e;
        return null;
    }

    function nodePrev(e) {
        while (e) if ((e = e.prevSibling).nodeType == 1) return e;
        return null;
    }

    // slideShow setup

    var
        slideShow = d.getElementById('slideShow'),
        slideCounter = d.getElementById('slideCounter'),
        firstSlide = nodeFirst(slideShow),
        lastSlide = nodeLast(slideShow),
        currentSlide = firstSlide,
        swapCounter;

    classAdd(slideShow, 'ss_scripted');
    classAdd(currentSlide, 'ss_show');

    // slideShow functions

    function showCounter() {
        textReplace(slideCounter, 
            Math.floor(swapCounter / 3600) + ':' +
            (Math.floor(swapCounter / 60) % 60) + ':' +
            swapCounter % 60
        );
    }

    function resetCounter() {
        swapCounter = swapTotal;
        showCounter();
    }

    function makeSlide(newSlide) {
        classRemove(currentSlide, 'ss_show);
        currentSlide = newSlide;
        classAdd(currentSlide, 'ss_show');
    }

    function nextSlide() { 
        resetCounter();
        var newSlide = nodeNext(currentSlide);
        if (newSlide) makeSlide(newSlide);
            else if (loopSlideShow) makeSlide(firstSlide);
    }

    function prevSlide() {
        resetCounter();
        var newSlide = nodePrev(currentSlide);
        if (newSlide) makeSlide(newSlide);
            else if (loopSlideShow) makeSlide(lastSlide);
    }

    function slideUpdate() {
        if (swapCounter--) showCounter(); else nextSlide();
    }

    function startSlideShow() {
        resetCounter();
        setInterval(slideUpdate, 1000);
    }

    // wait for onload to actually start the countdown 

    if (window.eventListener) w.addEventListener('load', startSlideShow, false);
        else w.addEventListener('onload', startSlideShow);

})(document);
这是css代码:

.ss_scripted img { display:none; }
.ss_scripted .ss_show { display:block; }

问题是您缺少一个“)”

试一试

while($imgPath=readdir($handle))!==false)如果(
in_数组(
strtolower(路径信息($imgPath,路径信息扩展)),
$允许的类型
))回声'
';
closedir($handle);
))echo'
第一个来自
数组()
第二个来自
if()


希望这有帮助!:D

看起来您忘记用括号关闭if语句了

试试这个

)) echo '

可读性很差,并且应该有句点的地方有逗号,并且缺少一个括号:

while (($imgPath = readdir($handle)) !== false) {
  $needle = strtolower(pathinfo($imgPath, PATHINFO_EXTENSION));
  // YOU WERE MISSING A CLOSING ( ON YOUR IF
  if (in_array($needle, $allowed_types)) {
    // THESE PERIODS WERE COMMAS
    echo '<img src="' . $imageDir . '/' . $imagePath . '" alt="slide" />';
  }
}

closedir($handle);
while(($imgPath=readdir($handle))!==false){
$needle=strtolower(路径信息($imgPath,路径信息扩展));
//你错过了一个结束(关于你的IF)
if(在_数组中($needle,$allowed_类型)){
//这些时期是逗号
回声';
}
}
closedir($handle);
注意,在本例中,我还将使用
printf
,而不是echo:

printf(“”,$imgDir,$imgPath);

您缺少的一个“')在回显之前,您可以将javascript代码放在下面的底部:

<script type="text/javascript" src="slideShow.js"></script> 

您忘记了while循环和if语句的大括号

也许这就是你想要的:

while (($imgPath = readdir($handle)) !== false){
    if (in_array(strtolower(pathinfo($imgPath, PATHINFO_EXTENSION)),$allowed_types)){
      echo '<img src="', $imageDir, '/', $imagePath, '" alt="slide" />';
    }
}
while(($imgPath=readdir($handle))!==false){
if(在数组中(strtolower(路径信息($imgPath,路径信息扩展)),$allowed\u类型)){
回声';
}
}
<script type="text/javascript" src="slideShow.js"></script> 
while (($imgPath = readdir($handle)) !== false){
    if (in_array(strtolower(pathinfo($imgPath, PATHINFO_EXTENSION)),$allowed_types)){
      echo '<img src="', $imageDir, '/', $imagePath, '" alt="slide" />';
    }
}