kukala
kukala
  • 发布:2017-04-23 22:39
  • 更新:2017-04-24 20:42
  • 阅读:3215

mui JS 倒计时没有用?

分类:MUI

<script type="text/javascript">
var alltime=5;
function kaishi(){
document.getElementById("test").innerHTML=alltime;
alltime--;
if(alltime==0){
clearTimeout(t);
}
}
t=setInterval("kaishi()",1000);
</script>
web端没有问题,放到mui里面调试没有反应,不知道为什么?

2017-04-23 22:39 负责人:无 分享
已邀请:
kukala

kukala (作者)

倒计时OK了,原来是再加个function就可以了,现在还有个问题是倒计时计数不完整,代码如下,应该alltime为0时结束的,现在的问题是alltime为1时显示不出来,不知道为什么?求助

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />  
    <title></title>  
    <script src="js/mui.min.js"></script>  
    <link href="css/mui.min.css" rel="stylesheet"/>  
    <link href="css/style.css" rel="stylesheet"/>  

</head>  
<body>  
    <div id="mui-start" style="display:none;position:relative;">  
        <a href="main.html"><img id="startimg"></a><a href="#" style="background-color:rgba(0,0,0,0.3);padding:5px;position:absolute;top: 10px;right: 10px;font-size: 14px;color:#FFFFFF;display:none" id="daoshu"></a>  
    </div>  
    <header id="mui-header" class="mui-bar mui-bar-nav" style="display:none;background-color:#32C78C;">  
    </header>  
    <div id="mui-content" class="mui-content" style="display: none;">  

    </div>  
    <!--底部-->  
    <nav id="mui-footer" class="mui-bar mui-bar-tab" style="display: none;">  

        </nav>  
</body>  
<script type="text/javascript" charset="utf-8">  
    mui.init({  
    });  

    mui.plusReady(function() {  
        //首页内容显示  
        function showIndex(){  
            plus.navigator.setFullscreen(false);  

            document.getElementById("mui-start").style.display="none";  
            document.getElementById("mui-content").style.display="block";  
            document.getElementById("mui-header").style.display="block";  
            document.getElementById("mui-footer").style.display="block";  
        }  
        //开始页面显示  
        function showStart(){  
            document.getElementById("mui-start").style.display="block";  
            document.getElementById("mui-header").style.display="none";  
            document.getElementById("mui-content").style.display="none";  
            document.getElementById("mui-footer").style.display="none";  

            plus.navigator.setFullscreen(true);  

            var sh = plus.navigator.getStatusbarHeight();   //获取系统状态栏高度  
            var h = plus.screen.resolutionHeight;   //获取设备屏幕高度分辨率  
            var w = plus.screen.resolutionWidth;    //获取设备屏幕宽度分辨率  
            var ObjStart=document.getElementById("mui-start");  

            ObjStart.style.height=h+"px";  
            ObjStart.style.backgroundColor="#2FB074"  

            var ObjDaoShu=document.getElementById("daoshu");  
            ObjDaoShu.style.display="block";  

            var alltime=3;  
            var t;  
            function daoJiShi(){  
                ObjDaoShu.innerHTML=alltime+"秒跳过";            
                alltime=alltime-1;        
                if(alltime=='0'){  
                    clearTimeout(t);  
                    showIndex();  
                }  
            }  
            t=setInterval(function() {  
                daoJiShi();  
            }, 1000);  

        }  

        showStart();  

    });  

</script>  
</html>
LLgg

LLgg

把判断等于0改为-1,就可以了

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />  
    <title></title>  
</head>  
<body>  
<div id="z"></div>  
</body>  
<script>  

            var zxlmweb=3;  
            var t;  
            function pq(){  
              document.getElementById("z").innerHTML=zxlmweb+"秒跳过"    
                zxlmweb=zxlmweb-1;        
                if(zxlmweb=='-1'){  
                    clearTimeout(t);  
                    showIndex();  
                }  
            }  
            t=setInterval(function() {  
                pq();  
            }, 1000);  
    </script>  
</html>

这是我的网站,O(∩_∩)O谢谢支持----->>中旋网ZxlmWeb

  • kukala (作者)

    感谢回复,代码是没问题!

    2017-04-24 20:43

kukala

kukala (作者)

如果我把daoJiShi()里的showIndex()方法屏蔽掉就正常了,不知道为什么?

<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="utf-8">  
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />  
    <title></title>  
    <script src="js/mui.min.js"></script>  
    <link href="css/mui.min.css" rel="stylesheet"/>  
    <link href="css/style.css" rel="stylesheet"/>  

</head>  
<body>  
    <div id="mui-start" style="display:none;position:relative;">  
        <a href="main.html"><img id="startimg"></a><a href="#" style="background-color:rgba(0,0,0,0.3);padding:5px;position:absolute;top: 10px;right: 10px;font-size: 14px;color:#FFFFFF;display:none" id="daoshu"></a>  
    </div>  
    <header id="mui-header" class="mui-bar mui-bar-nav" style="display:none;background-color:#32C78C;">  
    </header>  
    <div id="mui-content" class="mui-content" style="display: none;">  

    </div>  
    <!--底部-->  
    <nav id="mui-footer" class="mui-bar mui-bar-tab" style="display: none;">  

        </nav>  
</body>  
<script type="text/javascript" charset="utf-8">  
    mui.init({  
    });  

    mui.plusReady(function() {  
        //首页内容显示  
        function showIndex(){  
            plus.navigator.setFullscreen(false);  

            document.getElementById("mui-start").style.display="none";  
            document.getElementById("mui-content").style.display="block";  
            document.getElementById("mui-header").style.display="block";  
            document.getElementById("mui-footer").style.display="block";  
        }  
        //开始页面显示  
        function showStart(){  
            document.getElementById("mui-start").style.display="block";  
            document.getElementById("mui-header").style.display="none";  
            document.getElementById("mui-content").style.display="none";  
            document.getElementById("mui-footer").style.display="none";  

            plus.navigator.setFullscreen(true);  

            var sh = plus.navigator.getStatusbarHeight();   //获取系统状态栏高度  
            var h = plus.screen.resolutionHeight;   //获取设备屏幕高度分辨率  
            var w = plus.screen.resolutionWidth;    //获取设备屏幕宽度分辨率  
            var ObjStart=document.getElementById("mui-start");  

            ObjStart.style.height=h+"px";  
            ObjStart.style.backgroundColor="#2FB074"  

            var ObjDaoShu=document.getElementById("daoshu");  
            ObjDaoShu.style.display="block";  

            var alltime=3;  
            var t;  
            function daoJiShi(){  
                ObjDaoShu.innerHTML=alltime+"秒跳过";              
                alltime=alltime-1;        
                if(alltime=='0'){  
                    clearTimeout(t);  
                    //showIndex();  
                }  
            }  
            t=setInterval(function() {  
                daoJiShi();  
            }, 1000);  

        }  

        showStart();  

    });  

</script>  
</html>

该问题目前已经被锁定, 无法添加新回复