搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
JavaScript 教程
JS 浏览器BOM
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>JavaScript Window Location示例 - 基础教程(div.cn)</title> <body> <p>Click the button to return the hostname of the current URL:</p> <button onclick="myFunc()">点我试试</button> <p id="output"></p> <script> function myFunc() { var x = location.hostname; document.querySelector("#output").innerHTML = x; } </script> </body> </html>
运行结果