警报框上的SetTimeOut [英] SetTimeOut on Alert Box

查看:110
本文介绍了警报框上的SetTimeOut的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您在本论坛中提供的所有帮助。
代表他人,我非常感谢,并希望让您理解。



与此同时,我需要解决这个问题。
在警报框中设置超时。

 <?php 
echo'
< script type = 文本/ javascript>
var t = setTimeOut(5000); // 5secs
alert(您的分数是:。$ score。'。);
if(t === TRUE){
//清除警报框
this.alert.OK = true;
window.location = index.php;
}
< / script>';
?>

请不要介意我的伪代码,这是我理解JavaScript的最错误方式。



我知道一切皆有可能-可以通过某种方式来应对挑战,但我实际上并没有真正的解决方案,因此我将它扔给了屋内的专家。



我们期待着大家一起度过这一挑战。
我仍​​然是您的忠实朋友。

解决方案

浏览器不允许在其警报上至少超时,到目前为止,这是不可能的。但这是可行的方法。使用html和css创建一个消息框。



php:

 < ?
...计算/获取分数
需要什么? $ b< html>
< head>
<元http-equiv = refresh content = 5; index.php /><!-5秒后重定向->
< / head>
< body>
< div class = message-box>
< label>您的分数是:<?$ score?>< / label>
< / div>
< / body>
< / html>

元标记将告诉浏览器5秒钟后重定向到给定页面。

编辑:如果不允许您将页面显示给用户,则动态得分由php变量给出。使用元标记,然后试试这个

 < ;? 
...计算/获取分数
需要什么?
< html>
< body>
< div class = message-box>
< label>您的分数是:<?$ score?>< / label>
< / div>
< / body>
< ;!-将标记放在此处不是一个好习惯,但是它将在页面加载后实现重定向的技巧->
< script>
setTimeout(function(){
location.assign( index.php); //<-重定向
的位置},5000); //<-5秒后重定向
< / script>
< / html>


Thanks for every bit of help that you have all rendered in this forum. On behalf of others, I am grateful and want to make you understand that.

Meanwhile, there is this quest that I need to get solved. Setting a timeout on an alert box. That is,

<?php
echo '
<script type="text/javascript">
var t = setTimeOut(5000); //5secs
alert("Your score is: ". $score. '.");
if(t === TRUE){
//clear alert box
this.alert.OK = true;
window.location = "index.php";
}
</script> ';
?>

Please do not mind my psudo-code. It's just my wrongest way of understanding javascript to work.

I know that everything is possible - there could be some way of getting around a challenge. But I do not really have the actual solution. And I am throwing it open to the gurus in the house.

Thanks in anticipation that we will all get through this challenge together. I remain your loyal friend.

解决方案

Browsers won't allow timeout on their alert, at-least as of now it is not possible. But here is possible way around. Create a message box with html and css.

php:

<?
  ... what required to compute/fetch the score
?>
<html>
  <head>
   <meta http-equiv="refresh" content="5;index.php"/><!-- redirect after 5 secs -->
  </head>
  <body>
   <div class="message-box">
    <label>Your score is:<?$score?></label>
   </div>
  </body>
</html>

The meta tag will tell the browser to redirect to the given page after 5 seconds. Mean while the page is displayed to the user with dynamic score given by the php variable.

EDIT: In case if you are not allowed to use meta tags then try this

<?
  ... what required to compute/fetch the score
?>
<html>
  <body>
   <div class="message-box">
    <label>Your score is:<?$score?></label>
   </div>
  </body>
  <!-- not a good practice to put tag here, but it will do the trick to redirect after page is loaded-->
  <script>
    setTimeout(function(){
       location.assign("index.php");//<-- where to redirect
    }, 5000); //<-- redirect after 5 secs
  </script>
</html>

这篇关于警报框上的SetTimeOut的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆