為什么倒計時那里不顯示。。
為什么倒計時不顯示。。。源代碼如下:
<!DOCTYPE html>
<html>
?<head>
? <title>瀏覽器對象</title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gkb"/> ??
?</head>
?<body>
? <!--先編寫好網頁布局-->
? <a href="www.xianlaiwan.cn/code">forback</a>
? <p>操作成功</p>
? <p><span id="count"></span>秒后回到主頁</p>
? <a href="www.baidu.com">返回</a>
? <script type="text/javascript"> ?
var num=5;
? function startCount() {
? ? document.getElementById("count").value=num;
? ? num=num-1;
? ?if(num>=0){
? ? ? ?setTimeout("startCount()",1000);
? ? ? ?}
? ? else{
? ? ? ? window.location.;
? ? } ? ?
? }
? ? //window.onload=startCount;
? ?setTimeout(startCount,0); ?
? ?//獲取顯示秒數的元素,通過定時器來更改秒數。
? ?//通過window的location和history對象來控制網頁的跳轉。
? ?
?</script>?
</body>
</html>
2016-01-29
要獲取或替換HTML元素的內容,需要用innerHTML屬性,所以你可以用一下代碼實現倒計時數字的顯示:
function startCount() {
????document.getElementById("count").innerHTML=num;
? ? num=num-1;
????if(num>=0){
????????setTimeout("startCount()",1000);
????}
? ? else{
????????window.location.;
????} ? ?
?}
2016-01-29
? function startCount() {
? ? document.getElementById("count").value=num;
? ? num=num-1;
? ?if(num>=0){
? ? ? ?setTimeout("startCount()",1000);
? ? ? ?}
? ? else{
? ? ? ? window.location.;
? ? } ? ?
? }
span沒有value這個屬性,你用文本框顯示時間試試