HTML Location assign() 方法
htmldomweb developmentfront end technology更新于 2025/12/26 19:56:17
HTML Location assign() 方法加载新的 HTML 文档,而不会从文档历史记录中替换当前 HTML 文档的 URL。
语法
以下是语法 −
location.assign(URL)
让我们看一个 HTML Location assign() 方法的示例 −
示例
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
text-align: center;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 20px;
width: 330px;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
</style>
<body>
<h1>HTML Location assign() Method Demo</h1>
<button class="btn" onclick="display()">Load Tutorialspoint</button>
<script>
function display() {
location.assign("https://tutorialspoint.com/");
}
</script>
</body>
</html>
输出

点击"加载 Tutorialspoint"按钮,在当前文档中加载 Tutorialspoint 文档 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

