1、返回web主机的域名
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>uvi</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body> <button id="btn" onclick="getLoc()">按钮</button>
<p id="ptime"></p>
<script>
function getLoc(){
//返回web主机的域名
document.getElementById("ptime").innerHTML = window.location.hostname;
}
</script> </body>
</html>
2、返回web主机的域名
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>uvi</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body> <button id="btn" onclick="getLoc()">按钮</button>
<p id="ptime"></p>
<script>
function getLoc(){
//返回web主机的域名
document.getElementById("ptime").innerHTML = window.location.pathname;
}
</script> </body>
</html>
其他方式类似。