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.org.cn: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.org.cn: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接口。