HTMLAnchorElement: port 屬性
HTMLAnchorElement 介面的 port 屬性是一個字串,其中包含 <a> 元素 href 的埠號。如果埠是協議的預設埠(ws: 和 http: 為 80,wss: 和 https: 為 443,ftp: 為 21),則此屬性包含一個空字串 ""。
可以設定此屬性來更改 URL 的埠。如果 URL 沒有 host 或其方案是 file:,則設定此屬性無效。它還會默默忽略無效的埠號。
有關更多資訊,請參閱 URL.port。
值
字串。
示例
從錨點連結獲取埠
js
// An <a id="myAnchor" href="https://mdn.club.tw:443/en-US/docs/HTMLAnchorElement"> element is in the document
const anchor = document.getElementByID("myAnchor");
anchor.port; // returns ''
js
// Another <a id="myAnchor" href="https://mdn.club.tw:8888/en-US/docs/HTMLAnchorElement"> element is in the document
const anchor = document.getElementByID("myAnchor");
anchor.port; // Returns:'8888'
規範
| 規範 |
|---|
| HTML # dom-hyperlink-port-dev |
瀏覽器相容性
載入中…
另見
- 它所屬的
HTMLAnchorElement介面。