วันพุธที่ 3 พฤษภาคม พ.ศ. 2560

การเขียน Interface HTML สำหรับทดสอบการเขียนโปรแกรม

การเขียน Interface HTML สำหรับทดสอบการเขียนโปรแกรม

บางทีการจะเขียนโปรแกรมมันก็จำเป็นจะต้องมีการแสดงผล เพื่อให้เราสามารถเห็นผลลัพธ์ของโปรแกรม

จากที่ใช้ nodejs มันก็ค่อนข้างจะยุ่งยาก ทำไงดีฟระ จะอธิบายให้มันง่ายๆ

สรุปว่า HTML นี่ละกันเบเบสุด แล้วก็ยังใช้ javascript เหมือนเดิม อีกทั้งจะแปลงไปใช้กับ nodejs ก้ทำได้เลย

มาจากตอนที่แล้วที่เราจะหัดเขียนโปรแกรม บวกลบคูณหาร แล้วมันจะมี Input , output

 <script language="javascript">
var num1=0, num2=0, operador=0;
function resultado() {
  if(document.form1.operation.value == "+")
  {  operador =1;  }
  else {}
    switch(operador)
    {
    case 1:
    num1 = parseInt(document.form1.screenA.value);
    num2 = parseInt(document.form1.screenB.value);
    document.form1.screen.value=num1+num2;
    break;
    }
}
</script>
<html>
<head><meta charset="utf-8"><title></title></head>
<style>
input {
font-family: Arial, Helvetica, sans-serif;
font-size: 15px;
border-radius:7px;
font-weight:bold;
color: #333;
padding: 4px 7px;
border: 1px solid #D6D6D6;
background: url(fb.png) top repeat-x;
min-height:20px;
cursor:pointer;
width:100%;
}
input:hover {
font-weight:bold;
color: #000;
border: 1px solid #000000;
background: url(fbx.png) bottom repeat-x;
min-height:20px
}
</style>
<body>
<form name="form1" action="" method="">
<table width="300" border="0" align="center" cellpadding="0" cellspacing="5">
 <tr>
   <td colspan="5"></td>
 </tr>
 <tr>
   <td><input type="text" name="screenA" id="screenA" style="width:100%"></td>
   <td align=center ><input type="text" name="operation" id="operation" style="width:50%"></td>
   <td><input type="text" name="screenB" id="screenB" style="width:100%"></td>
   <td><input type="button" name="igual" id="igual" value="="   onclick="resultado()"></td>
   <td><input type="text" name="screen" id="screen" style="width:100%"></td>
 </tr>
 <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
 </tr>
</table>
</form>
</body>






ทีนี้วิธีการรัน ใช้ web นี้ช่วยในการรัน script และสามารถ input output ได้ด้วย
https://www.w3schools.com/js/tryit.asp?filename=tryjs_myfirst

โดยให้ copy code ด้านไปไปใส่ใน link ง่ายๆ เลยดังรูป

ไม่มีความคิดเห็น:

แสดงความคิดเห็น