View Full Version : سوال: ایجاد تایمر با جاوا اسکریپت
milad_d993
دوشنبه 28 اسفند 1391, 20:55 عصر
سلام دوستان
این کد رو توی یه فیلم آموزشی طرف اجرا کرد ولی الان اجرا نمیشه... چرا؟؟؟
Tnx
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
var timer;
function Start()
{
timer = setTimeout("counter()",1000);
}
function Stop()
{
clearTimeout(timer);
}
function counter()
{
var c = document.getElementById("tf").value;
var i = parseInt(c);
i++;
alert ("");
document.getElementById("tf").value; = i;
}
</script>
</head>
<body>
<input type="button" value="Start" onclick="Start();" />
<input value="0" type="text" id="tf" readonly />
<input type="button" value="Stop" onclick="Stop();" />
</body>
</html>
saeedtrb
سه شنبه 29 اسفند 1391, 16:35 عصر
من اين كد درست كردم مي توني ازش استفاده كني
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>timer</title>
<style>
*
{
transition:all 1s;
-webkit-transition:all 1s;
}
#time
{
width:138px;
height:46px;
background-color:rgba(255, 31, 0, 0.55);
text-align:center;
}
#time p
{
text-align:center;
margin:0;
padding:0;
}
#minutes
{
width:45px;
height:20px;
float:left;
background-color:#0FF;
}
#seconds
{
width:45px;
height:20px;
float:left;
background-color:#CF9;
}
#milliseconds
{
width:45px;
height:20px;
float:left;
background-color:#C6C;
}
</style>
</head>
<body dir="rtl">
<div id="time" >
<p>زمان باقيمانده</p>
<p id="minutes"></p>
<p id="seconds"></p>
<p id="milliseconds"></p>
</div>
<script>
var minutes=1;
var seconds=0;
var milliseconds=100;
function startTime()
{
timerStop=setInterval("timer()",10);
}
function timer()
{
milliseconds-=1
if(milliseconds==-1)
{
seconds-=1
milliseconds=100;
}
if(seconds==-1)
{
minutes-=1;
seconds=5;
}
if(seconds==0&&minutes==0&&milliseconds==0)
{
clearInterval(timerStop)
alert("پايان")
}
if(minutes==0&&seconds<=30&&seconds%2==0)
{
div.setAttribute("style","background-color:red")
}
if(minutes==0&&seconds<=30&&seconds%2!=0)
{
div.setAttribute("style","background-color:green")
}
divMs=document.getElementById("milliseconds");
divS=document.getElementById("seconds");
divM=document.getElementById("minutes");
divMs.innerHTML=milliseconds
divS.innerHTML=seconds
divM.innerHTML=minutes
div=document.getElementById("time")
}
startTime()
</script>
</body>
</html>
saeedtrb
سه شنبه 29 اسفند 1391, 17:01 عصر
اين قسمت كدت ايراد داره
document.getElementById("tf").value; = i;
من كدتو اصلاح كردم اين شد
<body>
<p id="M"></p>
<input type="button" value="Start" onClick="Start();" />
<input value="0" type="text" id="tf" readonly />
<input type="button" value="Stop" onClick="Stop();" />
<script language="javascript">
var c = document.getElementById("tf").value;
var i=parseInt(c);
function Start()
{
timer = setInterval("counter()",1000);
}
function counter()
{
divM=document.getElementById('M');
divM.innerHTML=i;
i+=1;
}
function Stop()
{
clearTimeout(timer);
}
</script>
</body>
سلام دوستان
این کد رو توی یه فیلم آموزشی طرف اجرا کرد ولی الان اجرا نمیشه... چرا؟؟؟
Tnx
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
var timer;
function Start()
{
timer = setTimeout("counter()",1000);
}
function Stop()
{
clearTimeout(timer);
}
function counter()
{
var c = document.getElementById("tf").value;
var i = parseInt(c);
i++;
alert ("");
document.getElementById("tf").value; = i;
}
</script>
</head>
<body>
<input type="button" value="Start" onclick="Start();" />
<input value="0" type="text" id="tf" readonly />
<input type="button" value="Stop" onclick="Stop();" />
</body>
</html>
sahand540
یک شنبه 06 تیر 1395, 15:07 عصر
لطفا یه کد بذارید که بشه بعد از چند ثانیه صفحه را به یک صفحه دیگه ارسال کرد و یه صفحه دیگه باز بشه
Moien Tajik
یک شنبه 06 تیر 1395, 19:00 عصر
$(document).ready( function() {
window.setTimeout( function () {
location.href = "https://www.google.com";
}, 5000);
});
kb0y667
جمعه 01 مرداد 1395, 01:12 صبح
setTimeout("window.location='http://google.com';",5000);
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.