HTML href 屬性
<base> 元素的 href 屬性為所有相對 URL 設定基本 URL。 例如,基本 URL 為https://example.com/tutorials,對於所有的相對 URL,比如 /html, /java, /jquery 等,最後結果為-
https://example.com/tutorials/html https://example.com/tutorials/java https://example.com/tutorials/jquery
以下是語法 −
<base href="absolute_URL">
在上面,絕對的 _URL 是基本 URL 的絕對 url。 現在,讓我們看一個示例來實現 <base> 元素的 href 屬性 −
示例
<!DOCTYPE html> <html> <head> <base href="https://www.example.com/tutorials/"> </head> <body> <h2>Tutorials List</h2> <p><a href="java.html">Java Tutorial</a></p><p>(This will act as https://www.example.com/tutorials/java.html)</p> <p><a href="jquery.html">jQuery Tutorial</a></p><p>(This will act as https://www.example.com/tutorials/jquery.html)</p> <p><a href="blockchain.html">Blockchain Tutorial</a></p><p>(This will act as https://www.example.com/tutorials/blockchain.html)</p> <p><a href="python.html">Python Tutorial</a></p><p>(This will act as https://www.example.com/tutorials/python.html)</p> </body> </html>
輸出

在上述示例中,我們把基本 URL 設定為 −
<base href="https://www.example.com/tutorials/">
在我們引用java.html後,最終它起的作用類似於 −
https://www.example.com/tutorials/java.html
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP