HTML DOM中的DOM Anchor主机属性用于设置或返回主机名,并发布href属性值的一部分。
用法:
它返回主机属性。anchorObject.host
用于设置主机属性。anchorObject.host = hostname:port
属性值:它包含值hostname:port,它指定URL的主机名和端口号。
返回值:它返回一个字符串值,该字符串值表示URL的域名和端口号。
例:本示例返回主机属性。
HTML DOM Anchor host Property
GeeksForGeeks
DOM Anchor host Property
Welcome to
"http://www.example.com:4097/test.htm#part2"
Submit
style="color:green;
font-size:25px;">
function myGeeks() {
var x =
document.getElementById(
"GFG").host;
document.getElementById(
"sudo").innerHTML = x;
}
"
输出:
在单击按钮之前:
单击按钮后:
示例2:本示例设置主机属性。
HTML DOM Anchor host Property
GeeksForGeeks
DOM Anchor host Property
Welcome to
"http://www.example.com:4097/test.htm#part2"
Submit
style="color:green;
font-size:25px;">
function myGeeks() {
var x =
document.getElementById("GFG").host =
"www.geeksforgeeks.org:443";
document.getElementById(
"sudo").innerHTML = x;
}
"
输出:
在单击按钮之前:
单击按钮后:
支持的浏览器:下面列出了DOM Anchor主机属性支持的浏览器:
谷歌浏览器
Internet Explorer 10.0以上
Firefox
Opera
Safari