js 页面跳转的几种方式
①location.assign(‘URL值’); 页面跳转,有历史记录
②location = ‘URL值’; 页面跳转,有历史记录
③location.href = ‘URL值’; 页面跳转,有历史记录
④window.open(‘URL值’); 打开一个新的选项卡
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
window.onload = function () {
var btns = document.getElementsByTagName('button');
btns[0].onclick = function () {
location = './test.html';
};
btns[1].onclick = function () {
location.href = './test.html';
};
btns[2].onclick = function () {
location.assign('./test.html');
};
btns[3].onclick = function () {
window.open('./test.html');
}
}
</script>
</head>
<body>
<button>页面跳转1</button>
<button>页面跳转2</button>
<button>页面跳转3</button>
<button>页面跳转4</button>
</body>
</html>