การทำ ให้ Button นับ ถอยหลัง
1. Copy Script ส่วนนี้ไว้ใน ส่วนของ Head
<script type="text/javascript">
function countdown(id){
i =id -1;//ให้ค่าลดลงทีละ 1 if(id > 1){
document.getElementById("bt_download").value ='Wait '+i+' Second..';
}else{
//เมื่อค่า i == 1
document.getElementById("bt_download").value ='Download Now';
document.getElementById("bt_download").disabled ='';
}
setTimeout("countdown("+i+")", 1000); //1000 = 1 วินาที
}
</script>
2.Copy Script นี้ไว้ที่ Body
<body onLoad="countdown('10')">
เพื่อเริ่มนับถอยหลังจาก 10 ถึง 0
onLoad="countdown('10')" เมื่อเปิดหน้าเว็บ มาให้เรียกใช้ฟังก์ชั่น countdown();
3.Copy Script นี้ไว้ใน Body
<form id="frm_download" name="frm_download" method="post" action="#">
<input name="bt_download" type="submit" id="button" value="Wait 10 Second.." disabled="disabled" />
</form>
4.ผลก็คือ
|