Javascript 向PHP数组添加标签

Javascript 向PHP数组添加标签,javascript,php,Javascript,Php,这是我的完整代码: <?php require_once ("comconfig.php"); require_once ("../function.php"); if (isset ($_COOKIE["accessattempt"]) && !$access_code_required) { setcookie("accessattempt", "", time()-3600); } ?> <!DOCTYPE html> <html l

这是我的完整代码:

<?php
require_once ("comconfig.php");
require_once ("../function.php");

if (isset ($_COOKIE["accessattempt"]) && !$access_code_required) {
    setcookie("accessattempt", "", time()-3600);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
    <title><?php echo $sitename; ?>Name of page</title>
    <script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="../js/jquery.easing.min.js"></script>
    <script type="text/javascript">
        var wubai = true;
    </script>
    <script type="text/javascript" src="../js/script.js"></script>
    <?php 
        if (!empty ($css)) 
        echo "<link type='text/css' rel='stylesheet' href='".$css."'>\r\n";
    ?>
</head>

<body>
    <a name="top" id="top">gotop</a>

    <ul class="nav" style="position: fixed;height: auto">
    <a href="#top" target="_self"><img src="../images/iconInputSearchClean.png" /></a>
    <?php 
    $all_letters = array('33','35','40','45','50','60');
        for($i=0;$i<count($all_letters);$i++){

            echo "<li style='padding: 2px 0' id='short_index' class='$all_letters[$i]'>"."$all_letters[$i]".'</li>';
        }
    ?>    
    </ul>
    <?php if (file_exists ($header)) include ($header); ?>
    <div class='style8' style="height: auto">Name of page</button></div></a></div>
    <p align='center'>
    <table>
        <tr>
            <td>

            <table class="select_descript" cellspacing="4" cellpadding="0" border="0" align="center" valign="middle"><tbody><tr><td>Name of page</td></tr></tbody></table>
            <p class="style_tweaks11">

            <?php
            $file = 'songfile.txt';
            $content = file_get_contents($file);
            $array = explode("\r\n", $content);
            for($i=0; $i<count($array); $i++)
            {
                $array1 = explode(" - ", $array[$i]);
                $artists[]=$array1["0"];
                $songname[]=$array1["1"];
            } 
            for($i=0; $i<count($artists); $i++){
                echo "<div class='songdetail'>
                        <form method=\"post\" action=\"".$script."\" name=\"top20_form\" onsubmit=\"return check()\">
                            <input type=\"hidden\" name=\"rq\" value=\"NA\">
                            <input type=hidden name=request_artist value=\"$artists[$i]\">
                            <input type=hidden name=request_title value=\"$songname[$i]\">
                            <input type=hidden name=func value='Send Your Request'>
                            <button type=submit name='submit' class=submit_button onclick='javascript:setCookie();'><div class='changeline' id='".(1+$i)."'>".(1+$i).". ".$artists[$i]." - ".$songname[$i]."</div></button>
                        </form>
                    </div>";
                }
            ?>
            </td>
        </tr>
    </table>
    </p>
</body>
</html>
我特别关注这一部分:

<?php 
    $all_letters = array('33','35','40','45','50','60');
        for($i=0;$i<count($all_letters);$i++){

            echo "<li style='padding: 2px 0' id='short_index' class='$all_letters[$i]'>"."$all_letters[$i]".'</li>';
        }
    ?>
这段代码基本上在屏幕的右上角添加了一个基于javascript的浮动菜单,请参见

这个菜单的目的是,在一个文本文件中有一个歌曲列表,这个PHP文件指的是songfile.txt。文本文件中有779首歌曲,这个PHP脚本获取所有779首歌曲,并将它们列在网站上。小javascript菜单的作用是允许我显示一系列数字,用户可以点击任何数字,并被带到页面上的确切位置


我想做的是添加标签来代替小javascript菜单中显示的数字,标签是供用户查看的,但在下面,我需要确保菜单的功能保持不变,当单击菜单项时,用户会被带到页面上的这个位置

将其更改为类似此索引数组的内容

<?php 
   $all_letters = array(array('33' ,"SonG Name"),array('35', "Song Name"));
   for($i=0;$i<count($all_letters);$i++){
       echo "<li style='padding: 2px 0' id='short_index' class='".$all_letters[$i][0]."'></label>".$all_letters[$i][1]."</label></li>";
    }
?>

单击“如果”将URL更改为/33或/35。如果您复制了它,但它仍然没有输出任何东西,问题就出在其他地方。

您将从哪里获取标签?至于标签,我将在代码中硬编码。不确定您想要什么,但这似乎不起作用,当我在脚本中添加这个新的代码snipit来替换以前的代码snipit时,我保存了它,网页显示为空白。我想你是想给你指路,而不是为你写代码。使用来自服务器的响应更新您的答案。没有响应,当我刷新页面时只有一个空白页面
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

<?php

$all_letters = [
    "label1" => '33',
    "label2" => '35'
];

foreach ($all_letters as $label => $value) {
    echo "<li class='$value'><a href='#$value'>$label</a></li>";
}

?>

</body>
</html>
*label1
*label2