Location对象
任务
在右边编辑器script标签内,获取当前显示文档的URL,并输出。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>location</title>
</head>
<script type="text/javascript">
document.write(location.protocol+"//"+location.hostname+location.port+location.pathname+location.search+location.hash+"<br>");
function currenturl(){
alert(window.location);
}
</script>
</head>
<body>
<input type="button" value="获取网页地址" onclick="currenturl()">
</body>
</html>
本文介绍了Location对象的基本用法,包括如何获取或设置窗体的URL,以及如何使用Location对象的属性来解析URL。通过示例代码展示了如何输出当前文档的完整URL。



7664

被折叠的 条评论
为什么被折叠?



