簡體   English   中英

使用php動態更改href值

[英]dynamically change href value using php

我有這個問題,我需要在錨中更改href的目錄地址,我希望使用php使其起作用。例如,如果我在首頁鏈接中,我的href值將是“ index.php”但是,如果im在產品文件夾的鏈接內部href值更改為“ ../index.php”,因為標題僅包含在每個頁面中..而且,如果您可以提出其他建議,我會很高興聽到..謝謝!

<div class="header_link">
     <a href="../"><div class="links"><p>Home</p></div></a>
     <a href="products/"><div class="links"><p>Products</p></div></a>
     <div class="links"><p>Packages</p></div>
     <div class="links"><p>Price List</p></div>
</div>

您應該使用絕對路徑而不是相對路徑。 相對路徑將變得難以管理,而且正如您所發現的,它們必須根據正在查看的頁面進行更改。

無需鏈接到../index.php ,只需鏈接到/index.php 無論您在哪個頁面上,它都將起作用。

嘗試在HTML的<head>中使用基本標記。

<base href="http://www.mysite.com">

要么

使所有href值都來自域絕對。

<a href="/index.php">Home</a>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM