HTML DOM 锚 origin 属性
HTML DOM 锚 origin 属性返回 href 属性值的协议、主机名和端口号,例如, http://www.demo.com:6064
以下是语法−
anchorObj.origin
现在,我们举一个示例来说明如何实现 DOM Anchor origin 属性 −
示例
<!DOCTYPE html> <html> <body> <h1>Company</h1> <p><a id="mylink" hreflang="en" href="http://www.abc.com:6064/abc/products.html">Products</a></p> <h2 id="myid"></h2> <button onclick="display()">Display href Part</button> <button onclick="display2()">Display origin</button> <button onclick="display3()">Display hreflang</button> <script> function display() { var a = document.getElementById("mylink").href; document.getElementById("myid").innerHTML = a; } function display2() { var a = document.getElementById("mylink").origin; document.getElementById("myid").innerHTML = a; } function display3() { var a = document.getElementById("mylink").hreflang; document.getElementById("myid").innerHTML = a; } </script> </body> </html>
输出
点击“显示来源”按钮−
广告