<html> <head> <title>ThaiCreate.Com Tutorial</title> </head> <body> <form name="frmMain" action="" method="post"> <script language="JavaScript"> var num = new Number(15.4567); document.write(num.toFixed()+"<br />"); document.write(num.toFixed(1)+"<br />"); document.write(num.toFixed(2)+"<br />"); document.write(num.toFixed(3)+"<br />"); document.write(num.toFixed(10)); </script> </form> </body> </html>
<html> <head> <title>ThaiCreate.Com Tutorial</title> </head> <body> <form name="frmMain" action="" method="post"> <script language="JavaScript"> function fncSum() { if(isNaN(document.frmMain.txtNumberA.value) || document.frmMain.txtNumberA.value == "") { alert('(Number A)Please input Number only.'); document.frmMain.txtNumberA.focus(); return; } if(isNaN(document.frmMain.txtNumberB.value) || document.frmMain.txtNumberB.value == "") { alert('(Number B)Please input Number only.'); document.frmMain.txtNumberB.focus(); return; } document.frmMain.txtNumberC.value = (parseFloat(document.frmMain.txtNumberA.value) + parseFloat(document.frmMain.txtNumberB.value)).toFixed(2); } </script> Number A <input type="text" name="txtNumberA" value=""> <br> Number B <input type="text" name="txtNumberB" value=""> <br> A + B = <input type="text" name="txtNumberC" value=""><br> <input type="button" name="btnSum" value="Sum" OnClick="fncSum();"> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท