代码之家  ›  专栏  ›  技术社区  ›  ian

要链接的url前面的代码

  •  1
  • ian  · 技术社区  · 15 年前

    出于某种原因,我的PHP正在将页面URL添加到我的链接中。

    # 出柜 mysite.com/url_the_page/page.php# 你知道这是什么原因吗?

    echo'<a href="#" id="bb">click me</a></span>';
    echo '<a href="#" id="song_'. $row[id].'">';
    echo $artist_title;
    echo '</a></span>';`
    

    完整代码:

    while ($row = mysql_fetch_array($query))
        {
    
            if ($row[sourcefile] !== NULL )
            {
    
    
                echo '';
    
    
                if ( $row[artist] !== NULL && $row[title] !== NULL)
                {
                    $artist_title = $row[artist] . ' - ' . $row[title];
                }
                else
                {
                    $artist_title = $row[originalfilename];
                }
    
    
    
                echo "<a href=http://".$row[link].' target="_blank">LINK</a> - ';
    
                if ( $row[listened] == 0)
                {
                    $link_class = "unlistened";
                }
                else
                {
                    $link_class = "listened";
                }
    
                $size = $row[size];
                $size = round(($size / 1000000),2);
    
                if ( $size > 30 )
                {
                    echo '<font color="red">MIX </font>';
                }
    
                echo '<span id="'.$row[id].'" class="'.$link_class.'">';                
    
                echo '<a href="#" id="song_'. $row[id].'">';
                echo $artist_title;
                echo '</a></span>';
    
                echo ' - ';
    
                //turn size into MB
                $size = $row[size];
                $size = round(($size / 1000000),2);
    
                //if the song is smaller than a certain size display the size as red.   
                if ( $row[size] < 1500000)
                {
                    echo '<font color="red">';
                    echo $size;
                    echo '</font>';
                }
                else
                {
                    //echo $row[size];
                    echo $size;
                }
    
                echo 'MB<br>';
    
            }
        }
    
    2 回复  |  直到 13 年前
        1
  •  5
  •   Pekka    15 年前

    这与PHP无关,而是浏览器的默认行为。

    # 不是有效的URL,而是所谓的 Fragment Identifier. 它在url中有一个特殊的含义,即指示浏览器在目标文档中查找该名称的锚定。指向的URL # 只会指向当前文档的开头。

        2
  •  1
  •   Christophe    15 年前

    据我所知,这是一个正常的行为,如果你有一个与名称类别的链接,例如:

    <a name="categories"></a>
    

    然后使用以下url链接到页面的该部分

    mysite.com/index.html#categories
    
    推荐文章