gpt4 book ai didi

javascript - 将键盘控件插入图像查看器库脚本

转载 作者:行者123 更新时间:2023-12-03 12:13:34 25 4
gpt4 key购买 nike

我想将键盘控制左箭头和右箭头键添加到此处的脚本中:

http://xenforo.com/community/threads/php-file-that-basically-functions-as-folder-image-viewer.14658/

左箭头 = 后退,右箭头 = 下一步。

每次我把函数放在前面?>它总是返回错误。

我用这个方法

jQuery keypress left/right navigation

$("document").keypress(function (e) { //always error here
if(e.keyCode == 37) { // left
//back (what here next i don't know too)
}
else if(e.keyCode == 39) { // right
//next
}
});

这是完整的脚本

<?php
// ------------------------------------------------------------------------- //
// Comic Gallery 1.2 //
// ------------------------------------------------------------------------- //
// Copyright (C) 2005 Stuart Robertson //
// http://www.designmeme.com/ //
// ------------------------------------------------------------------------- //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// A summary is available at http://creativecommons.org/licenses/GPL/2.0/ //
// ------------------------------------------------------------------------- //
// Edit the code below to configure your Comic Gallery //
// ------------------------------------------------------------------------- //

// Your images directory, relative to the page calling this script
$imagedir="comics";

// To start at the last image use "last"
$startimage="first";

// Copyright name to display, for none use " "
$copyright=" ";

// Creative Commons license, for none use " "
// example: "http://creativecommons.org/licenses/by/2.0/"
$creativecommons=" ";

// type of divider, for none use " "
$divider="&middot;";

// show arrows, for none use 0
$arrows=1;

// show back and next, for none use 0
$backnext=1;

// show back and next, for none use 0
$firstlast=1;

// show numbers, for none use 0
$numbers=1;

// numbers per line
$linelength=10;

// navigation position, for aboe use "above"
$navplacement="below";

// ------------------------------------------------------------------------- //
// Do not edit below this line
// ------------------------------------------------------------------------- //

// initialize variables
$pics=array();
$count=0;

// Open the directory
$comicdir=opendir($imagedir);

// read directory into pics array
while (($file = readdir($comicdir))!==false) {
// filter for jpg, gif or png files...
if (substr($file,-4) == ".jpg" || substr($file,-4) == ".gif" || substr($file,-4) == ".png" || substr($file,-4) == ".JPG" || substr($file,-4) == ".GIF" || substr($file,-4) == ".PNG"){
$pics[$count] = $file;
$count++;
}
}
closedir($comicdir);

// check for the picture to view
$pic=$_GET['p'];
// if no picture variable...
if ($pic=="") {
if ($startimage!="last"){ $pic=1; }
else { $pic=$count; }
}

// sort the filenames alphabetically
sort($pics);
reset($pics);

// determine which picture to get
for ($f=0;$f<=sizeof($pics)-1;$f++){if ($pic==$pics[$f]){$selected = $f+1;}}

// check for javascript...
if ($pic && !preg_match("/javascript/",$pic)){

// get current image file
$current=$pics[$pic-1];
$next=$pic+1;
if ($next > sizeof($pics)){ $next=sizeof($pics); }
$back=$pic-1;
if ($back < 1){ $back=1; }

// display image above nav
if ($navplacement!="above"){
if (substr($current,-4) == ".jpg" || substr($current,-4) == ".gif" || substr($current,-4) == ".png" || substr($current,-4) == ".JPG" || substr($current,-4) == ".GIF" || substr($current,-4) == ".PNG"){
if ($pic < sizeof($pics)){
echo"\n<p id=\"cg_img\"><a href=\"?p=".$next."\"><img src=\"".$imagedir."/".$current."\" alt=\"Next\" /></a></p>\n";
} else {
echo"\n<p id=\"cg_img\"><img src=\"".$imagedir."/".$current."\" alt=\"End\" /></p>\n";
}
}
}

// display back and next
if ($backnext != 0 || $arrows != 0){
if (sizeof($pics) > 1){
echo "<p id=\"cg_nav1\">";
if ($firstlast != 0){
if ($pic > 1){ echo "<a href=\"?p=1\" id=\"cg_first\"><span>First</span></a>"; }
else { echo "<span id=\"cg_first\"><span>First</span></span>"; }
echo "<span class=\"cg_divider\"> ".$divider." </span>";
}
if ($pic > 1){
echo "<a href=\"?p=".$back."\" id=\"cg_back\"><span>";
if ($arrows != 0) { echo "&laquo; "; }
if ($backnext != 0) { echo "Back"; }
echo "</span></a>";
} else {
echo "<span id=\"cg_back\"><span>";
if ($arrows != 0) { echo "&laquo; "; }
if ($backnext != 0) { echo "Back"; }
echo "</span></span>";
}
echo "<span class=\"cg_divider\"> ".$divider." </span>";
if ($pic < sizeof($pics)){
echo "<a href=\"?p=".$next."\" id=\"cg_next\"><span>";
if ($backnext != 0) { echo "Next"; }
if ($arrows != 0) { echo " &raquo;"; }
echo "</span></a>";
} else {
echo "<span id=\"cg_next\"><span>";
if ($backnext != 0) { echo "Next"; }
if ($arrows != 0) { echo " &raquo;"; }
echo "</span></span>";
}
if ($firstlast != 0){
echo "<span class=\"cg_divider\"> ".$divider." </span>";
if ($pic < sizeof($pics)){ echo "<a href=\"?p=". sizeof($pics) ."\" id=\"cg_last\"><span>Last</span></a>"; }
else { echo "<span id=\"cg_last\"><span>Last</span></span>"; }
}
echo "</p>\n";
}
}

// display numbers
if ($numbers != 0){
if (sizeof($pics) > 1){
// display textlinks
echo "<p id=\"cg_nav2\">";
// loop over images
for ($f=1;$f<=sizeof($pics);$f++){
// if the link to the pic is the selected one, display a bold number and no link
if ($pic==$f){echo "<b>".$f."</b>";}
// otherwise display the link
else{echo "<a href=\"?p=".$f."\">".$f."</a>";}
// add dividers and linebreaks
if (($f % $linelength) == 0) {
echo "<br />";
}
else {
if ($f!=sizeof($pics)){
echo "<span class=\"cg_divider\"> ".$divider." </span>";
}
}
}
echo "</p>\n";
}
}

// display image below nav
if ($navplacement=="above"){
if (substr($current,-4) == ".jpg" || substr($current,-4) == ".gif" || substr($current,-4) == ".png" || substr($current,-4) == ".JPG" || substr($current,-4) == ".GIF" || substr($current,-4) == ".PNG"){
if ($pic < sizeof($pics)){
echo"\n<p id=\"cg_img\"><a href=\"?p=".$next."\"><image src=\"".$imagedir."/".$current."\" alt=\"Next\" border=\"0\"></a></p>\n";
} else {
echo"\n<p id=\"cg_img\"><image src=\"".$imagedir."/".$current."\" alt=\"End\" /></p>\n";
}
}
}

// display copyright
echo "<p id=\"cg_credits\">";
if ($creativecommons != " "){ echo "<a href=\"".$creativecommons."\" title=\"Creative Commons License\">Some Rights Reserved</a> ".$divider." "; }
else {
if ($copyright != " "){ echo "&copy; ".$copyright." ".$divider." "; }
}
// If you make use of this script, be nice and keep the link back to my site :-)
echo "Powered by <a href=\"http://designmeme.blogspot.com/2005/05/comic-gallery-script.html/\">ComicGallery</a></p>\n";
}
?>

最佳答案

PHPJavaScript是两种独立的编程语言——你不能像这样将它们混合在一起。当您将 jQuery 方法直接放入 PHP 代码中时(例如,在“?>”之前,您是在告诉 PHP 运行该代码,但 PHP 不知道如何运行,因为它使用的是不同的语言。

相反,尝试将您的方法放在 PHP 标签之外 ( <? ... ?> ),或 echo方法,具体取决于页面其余部分的设置方式。

<小时/>

欢迎来到 Stack Overflow!

关于javascript - 将键盘控件插入图像查看器库脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24835912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com