HTMLAnchorElement:port 属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
HTMLAnchorElement
接口的 port
属性是一个字符串,包含 URL 的端口号。如果端口是该协议的默认值,则该属性为空字符串。
备注:
如果 HTMLAnchorElement
对象引用的 URL 不包含明确的端口号(例如,https://localhost
),或者包含的端口号是 URL 协议部分对应的默认端口号(例如,https://localhost:443
),那么 port
属性将是一个空字符串:''
。
值
一个字符串。
示例
从锚点链接获取端口号
js
// 文档中有一个 <a id="myAnchor" href="https://developer.mozilla.org:443/zh-CN/docs/HTMLAnchorElement"> 元素
const anchor = document.getElementByID("myAnchor");
anchor.port; // 返回“”
js
// 文档中的另一个 <a id="myAnchor" href="https://developer.mozilla.org:8888/zh-CN/docs/HTMLAnchorElement"> 元素
const anchor = document.getElementByID("myAnchor");
anchor.port; // 返回“8888”
规范
Specification |
---|
HTML # dom-hyperlink-port-dev |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
port |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
参见
- 所属接口
HTMLAnchorElement
。