|
 |
|
codeตั้งเวลานับถอยหลังโดยใช้ setTimeout มีปัญหาครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<script type="text/javascript" language="JavaScript">
var intval = ""
var nRate = 3 //ส่วนนี้ผมhardcode ไว้
function beginRefresh() {
if (intval == "") {
intval = window.setInterval("doRefresh()", 1000);
var obj_refresh = window.document.getElementById("refresh");
obj_refresh.innerHTML = '<INPUT type="checkbox" id="refresh_enable" value="'+nRate+'" onclick="beginRefresh();" checked><B>Auto Refresh '+nRate+' วินาที</B>';
} else {
window.clearInterval(intval);
intval = "";
var obj_refresh = window.document.getElementById("refresh");
obj_refresh.innerHTML = '<INPUT type="checkbox" id="refresh_enable" value="'+nRate+'" onclick="beginRefresh();"><B>Auto Refresh <INPUT type="text" id="refresh_rate" value="'+nRate+'" size="1" onChange="nRate=this.value;"> วินาที</B>';
}
}
function doRefresh() {
var obj_refresh = window.document.getElementById("refresh");
var obj_refresh_enable = window.document.getElementById("refresh_enable");
obj_refresh_enable.value --;
if (obj_refresh_enable.value <= 0) {
window.clearInterval(intval);
//window.location.reload();
document.getElementById("ttt").click(); //เมื่อครบกำหนดจะไปเรียกปุ่มที call ฟังก์ชัน bind gridview ใหม่ครับ
}
obj_refresh.innerHTML = '<INPUT type="checkbox" id="refresh_enable" value="'+obj_refresh_enable.value+'" onclick="beginRefresh();" checked><B>Auto Refresh '+obj_refresh_enable.value+' วินาที</B>';
}
//-->
</script>
ส่วนคอนโทรลครับ
<table>
<tr>
<td class="borderless" align="right" id="refresh">
<input type="checkbox" id="refresh_enable" runat="server" value="3" onclick="beginRefresh();"/><b>Auto Refresh
<input type="text" id="refresh_rate" value="3" size="1" onchange="nRate=this.value;"/> วินาที</b></td>
</tr>
</table>
ลองเปลี่ยน input เอานะครับ จากตัวอย่างเป็น checkbox
|
 |
 |
 |
 |
Date :
2010-11-05 02:15:36 |
By :
Manussawin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
code พี่ยากมากเลยครับ งง เลย อิอิ ขอบคุณ ครับ เดี่ยวลองทำดู
|
ประวัติการแก้ไข 2010-11-05 03:31:40
 |
 |
 |
 |
Date :
2010-11-05 03:31:22 |
By :
PISTOLA |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตัวนี้เป็น Code จับเวลาครับ
Code (JavaScript)
<body onLoad="begintimer()">
<script language="">
var limit="0:10"
if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function begintimer(){
if (!document.images)
return
if (parselimit==1)
// เหตุการณ์ที่ต้องการให้เกิดขึ้น
// window.location='page.php'; ถ้าต้องการให้กระโดดไปยัง Page อื่น
frmTest.submit();
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime="เวลาที่เหลือ <font color=red> "+curmin+" </font>นาที กับ <font color=red>"+cursec+" </font>วินาที "
else
if(cursec==0)
{
alert('หมดเวลาแล้วจ้า');
}
else
{
curtime="เวลาที่เหลือ <font color=red>"+cursec+" </font>วินาที "
}
document.getElementById('dplay').innerHTML = curtime;
setTimeout("begintimer()",1000)
}
}
//-->
</script>
<div id=dplay ></div>
<form name="frmTest" action="check.php">
// ใส่ Form
</form>
Go to : อยากได้ code ที่จับเวลาทำข้อสอบ แบบเลื่อนตามSCROLLBAR
|
 |
 |
 |
 |
Date :
2010-11-05 06:23:55 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับพี่ วิน แล้ว code ของผม error ตรงไหนละเนี่ย ><
|
ประวัติการแก้ไข 2010-11-05 14:43:43
 |
 |
 |
 |
Date :
2010-11-05 14:43:09 |
By :
PISTOLA |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมคิดว่าคุณอาจจะยังไม่ได้ส่งค่าไป หรือส่งไปเเล้ว แต่หน่วยที่เค้านับมันเป็น millisec ก็ต้องเอาไป * 1000 อีกทีคับ
อย่างผลใช้ jquery มันเป็นอย่างงี้ เอาของคุณมาแปลงอ่านะ
Code (PHP)
<head>
<script type="text/javascript" src="../library/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#btn_ok").click(function(){
var time = $("#text").val();
time = time*1000;
setTimeout("alert('time')",time);
});
});
</script>
<script type="text/javascript">
function timedMsg(text)
{
//text = text*1000;
var t=setTimeout("alert('5 seconds!')",text*1000)
}
</script>
</head>
<body>
<form>
<input type="text" name="text" id="text" />
<input type="button" value="Display timed alertbox!" id="btn_ok">
</form>
</body>
|
 |
 |
 |
 |
Date :
2010-11-05 15:36:52 |
By :
- - |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
jQuery CountDown รับรองแจ๋ม
|
 |
 |
 |
 |
Date :
2010-11-05 16:59:31 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับที่แนะ นำ ได้ความรู้ แนวทางมากเลย
|
 |
 |
 |
 |
Date :
2010-11-05 23:23:36 |
By :
PISTOLA |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือผมลอง ทำ แบบใช้ jquery ไมได้ครับ คือว่า ผมต้องเขียนหน้าเว็บ เเล้ว เขียนข้อมูลลงไปในบอร์ด dspic33 ปรากฎ ว่า มันไม่สามารถเรียก ไฟล์ jquery-1.4.2.min.js ได้อ่ะครับ ไม่ทราบว่า มี แบบอื่นไหม ครับ คือลอง ทุกความคิดเห็น ตัวบอร์ด มัน ใช้ setTimeout ได้แบบเีดียวครัลที่ไม่ error
|
 |
 |
 |
 |
Date :
2010-11-10 20:29:33 |
By :
PISTOLA |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|