倒计时5秒后跳转页面 为什么倒计时不动?

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

<script type="text/javascript">

function back(){

window.history.back();

}

var count=document.getElementById("count").innerHTML;

//获取倒计时的值

function count1(){

count--;

document.getElementById("count").innerHTML=count;

if(count==0){

location.assign("www.imooc.com");

}

}

setInterval("count1()",1000);

</script>

</head>

<body>

<h1>操作成功</h1>

<p><span id="count">5</span>秒后返回主页</p>

<a href="javascript:back();">返回</a>

</body>

</html>


觅己网
浏览 2001回答 3
3回答

stone310

变量count获取失败;将整段js代码放到下面,</body>的上方;补充一点,现在这么写不能加window.onload;如果将setInterval("count1()",1000)这种字符串写法改成setInterval(count1,1000)这么写,就可以加上window.onload;因为字符串写法只能获取全局作用域下的函数,而另一种函数写法则可获取到局部作用域中的函数;

慕的地8582982

KTIYIYPFNLIQGPFADTPLORVRIYOROYGDFJMHROEUJYUXDKAQUXNKGQGHWZXNPAWLNJAVZCSBFCYBEYURSCSVRAEOFVXAKAVLBKAJYTDTJZWZDMIRUWZIRTJZPSUXUDGEGPMJSUDMPYWSBLHLOQMWNRAJZVEAQMXNISOEUJLILBKAQFIGLCRVLHKZILBBSAXAWSCSBEDTCXGJYIRHXRECEUXNKGCZHJFBRIYGVZQIEADMWTJLOZYBQHYBSBDGXHJGRIXAPRUSWZJZPRTJYVRHLUKTJZPEUKMPEMCNWFOYBPMVENDGIQTJBWZCZQGWRUJRTGTMULSRISKHQNGQJZPSMNJMMUOPSVWJQQQKFSSWLSMHRKURJJZOISHFYHBUAXVLMINZPZTCPFPPJSBUIISPIPPKHWJHXUGWZZFBRWDHFLBERSVYJKTMUJAQEEQTRBULKXABHANHAAWMWJUBTEEMJZYSFVRADDTNVNXHLISIOOCZBJZBHJCMCJZYVMRUNXHQWWORRCVLUMJMZCSQQQQTTTPAJPQOKDCYILODAEGOKKFOVKGADCUSSSJKQWPFSBUKUWQTFSYUGWCMFVJBYCNTDJZXXKANQFPJTJZSPIFOKAZJTYLGMSJQXQLVYMSLIZLEHRVBFCSFZMIVJGJWTDJDOBUDWWCSIVLXUWHHVLIBPFSIWXLOOTJFYHDMDDCFMCMPORAHRWCIIPDFRSMMJJPOWAJJTBDOHQGULDKWNAPTPQZDHYUBKCPVUUHALEKUUDKQEEIYFXYEXKTAETEJWWKADEZTPNEMZQHHRUQOJAEPMTEEPQWNQNEBMQIVOGDALVJTAXOEWVMVZSCVUDXGIYOENDNWTITVLHYHDNPMIMBENXNDOWMW
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript