history的一个问题
来源:1-1 课程概述
慕雪1434180
2017-11-26 17:20:33
老师,请问这段代码有什么问题,在浏览器中无法显示效果?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>在浏览器历史中导航</title>
</head>
<body>
<button id="back">Back</button>
<button id="forward">Forward</button>
<button id="go">Go</button>
<script type="text/javascript">
var buttons=document.getElementsByTagName('button');
for (var i = 0; i < buttons.length; i++) {
buttons[i].onclick=handleButtonPress;
}
function handleButtonPress(e){
if (this.id=="back") {
window.history.back();
}
else if (this.id=="forward") {
window.history.forward();
}
else if (this.id=="go") {
window.history.go("http://www.apress.com");
}
}
</script>
</body>
</html>
1回答
小丸子爱吃菜
2017-11-27
实现这个效果是要有多个网页去配合的,才能实现back和forword,只有一个页面,无法实现该效果。
可以看下老师在课程中是如何去实现的。
祝学习愉快!
相似问题