为什么我的不能返回呢
前边贴的完整代码有误,重新贴一下,主要是前一个goback 没将()加上
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<h1>操作成功
<span id=miao>5</span>秒后回到主页<span onclick="goback()" style="color:blue">返回</span>
<script type="text/javascript">
var num=document.getElementById("miao").innerHTML;
function sec()
{
num=num-1;
document.getElementById("miao").innerHTML=num;
if(num==0)
{
window.location.replace("https://www.imooc.com/");
//window.history.forward(i);
}
}
setInterval(sec,1000);
function goback(){
window.history.back();
}
//获取显示秒数的元素,通过定时器来更改秒数。
//通过window的location和history对象来控制网页的跳转。
</script>
</body>
</html><!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<h1>操作成功
<span id=miao>5</span>秒后回到主页<span onclick="goback" style="color:blue">返回</span>
<script type="text/javascript">
var num=document.getElementById("miao").innerHTML;
function sec()
{
num=num-1;
document.getElementById("miao").innerHTML=num;
if(num==0)
{
window.location.replace("https://www.imooc.com/");
//window.history.forward(i);
}
}
setInterval(sec,1000);
function goback(){
window.history.back();
}
//获取显示秒数的元素,通过定时器来更改秒数。
//通过window的location和history对象来控制网页的跳转。
</script>
</body>
</html>首先,你这代码太乱了……请养成良好的书写习惯,其次是逻辑有问题,部分代码重复出现……
接下来说的你点击不能返回,你的返回函数是goback(),因此你的onClick="goback"请改为onClick="goback()"
修改后如下:
<script type="text/javascript">
var num=document.getElementById("miao").innerHTML;
function sec()
{
num=num-1;
document.getElementById("miao").innerHTML=num;
if(num==0)
{
window.location.replace("https://www.imooc.com/");
//window.history.forward(i);
}
}
setInterval(sec,1000);
function goback(){
window.history.back();
}
//获取显示秒数的元素,通过定时器来更改秒数。
//通过window的location和history对象来控制网页的跳转。
</script>