Javascript 使用警报确定按钮重定向不工作

Javascript 使用警报确定按钮重定向不工作,javascript,Javascript,我在网上找到了一个关于定时器的教程,并试图修改它。我添加了一个window.location.href=“typage.php”在警报原因之后,我已经读到,当单击警报上的ok按钮时,可以使用它重定向到页面 问题是,单击“确定”按钮后,它不会显示应该重定向的页面。相反,它仍然显示倒计时计时器并显示“未找到记录”。这是不正确的,因为我需要显示typage.php 我还可以将时间格式更改为mm:ss格式吗 测验 var-mins=1; var secs=分钟*60; 函数倒计时(){ setTim

我在网上找到了一个关于定时器的教程,并试图修改它。我添加了一个
window.location.href=“typage.php”在警报原因之后,我已经读到,当单击警报上的ok按钮时,可以使用它重定向到页面

问题是,单击“确定”按钮后,它不会显示应该重定向的页面。相反,它仍然显示倒计时计时器并显示“未找到记录”。这是不正确的,因为我需要显示typage.php

我还可以将时间格式更改为mm:ss格式吗


测验
var-mins=1;
var secs=分钟*60;
函数倒计时(){
setTimeout('Decrement()',60);
} 
函数减量(){
if(document.getElementById){
分钟=document.getElementById(“分钟”);
秒=document.getElementById(“秒”);
如果(秒<59){
秒。值=秒;
} 
否则{
minutes.value=getminutes();
seconds.value=getseconds();
} 
如果(分钟<1){
minutes.style.color=“红色”;
seconds.style.color=“红色”;
} 
如果(分钟<0){
警惕(“时间到了!”);
window.location.href=“typage.php”;
分钟。数值=0;
秒。值=0;
} 
否则{
秒--;
setTimeout('Decrement()',1000);
} 
} 
} 
函数getminutes(){
分钟=数学楼层(秒/60);
返回分钟;
} 
函数getseconds(){
返回秒-数学轮(分钟*60);
}
测验
剩余时间:
: 



您可以编写一个简单的
php
文件,该文件仅包含
window.location.href=“typage.php”
,并测试此php文件是否可以
重定向到所需的页面。

如果(document.getElementById){
确实没有必要,则此条件

var-mins=1;
var minutes=document.getElementById(“分钟”);
var seconds=document.getElementById(“秒”);
var secs=分钟*60;
函数倒计时(){
setTimeout('Decrement()',60);
}
函数减量(){
如果(秒<59){
秒。值=秒;
}否则{
minutes.value=getminutes();
seconds.value=getseconds();
}
如果(分钟<1){
minutes.style.color=“红色”;
seconds.style.color=“红色”;
}
如果(分钟<0){
警惕(“时间到了!”);
window.location.href=“typage.php”;
分钟。数值=0;
秒。值=0;
}否则{
秒--;
setTimeout('Decrement()',1000);
}
}
函数getminutes(){
分钟=数学楼层(秒/60);
返回分钟;
}
函数getseconds(){
返回秒-数学轮(分钟*60);
}

我想如果(document.getElementById){
,您可能需要检查这个答案?
<?php include ("inc/userheader.php");?>

<head>
    <meta charset="utf-8">
    <title>Quiz</title> 
<script> 
        var mins = 1; 

        var secs = mins * 60; 

        function countdown() { 
            setTimeout('Decrement()', 60); 
        } 

        function Decrement() { 
            if (document.getElementById) { 
                minutes = document.getElementById("minutes"); 
                seconds = document.getElementById("seconds"); 


                if (seconds < 59) { 
                    seconds.value = secs; 
                } 

                else { 
                    minutes.value = getminutes(); 
                    seconds.value = getseconds(); 
                } 

                if (mins < 1) { 
                    minutes.style.color = "red"; 
                    seconds.style.color = "red"; 
                } 

                if (mins < 0) { 
                    alert("Time's up!"); 
                    window.location.href = "typage.php";

                    minutes.value = 0; 
                    seconds.value = 0; 
                } 
                else { 
                    secs--; 
                    setTimeout('Decrement()', 1000); 
                } 
            } 
        } 

        function getminutes() { 
            mins = Math.floor(secs / 60); 
            return mins; 
        } 

        function getseconds() { 

            return secs - Math.round(mins * 60); 
        }

</script>

<body onload="countdown();"> 

<div class="container">
    <h1> Quiz</h1>


    <?php echo form_open('users/redirect/', ['class' => 'form-horizontal']);?> 
   <!-- onload function is evoke when page is load --> 
<!--countdown function is called when page is loaded --> 


    <div> 
        <b>Time Left :
        <input id="minutes" type="text" style="width: 10px; 
             border: none; font-size: 16px;  
            font-weight: bold; color: black;"><font size="5"> : 
                        </font> 
        <input id="seconds" type="text" style="width: 20px; 
                        border: none; font-size: 16px; 
                        font-weight: bold; color: black;"></b>
    </div> 

    <br>

    <?php if(count($questions) > 0):?>

        <?php $index = 1 ?>
        <?php foreach($questions as $row):?>
        <br>
        <div class="row justify-content-center view">
        <div class="col-lg-10">

        <p><?=$index++?>. <b><?=$row->ques?></b></p>

        <?php 
                $choices= array($row->ch_des1, $row->ch_des2, $row->ch_des3, $row->ch_des4);
                shuffle($choices);
            ?>

            <?php foreach($choices as $ch_des):?>
                <input type="radio" name="ch_id<?=$row->ch_id?>" value="<?=$ch_des?>"> <?=$ch_des?><br>
            <?php endforeach;?>

        </div>
        </div>
        <?php endforeach;?>
        <?php else:?>
            <tr>
                <td>No records found!</td>
            </tr>
    <?php endif;?>

        </div>
    </div>

        <br><br>
        <center><button type ="submit" class="btn btn-primary "> Submit </button></center>

    </form>


</div>
</body>


<?php include ("inc/footer.php");?>