สามารถแสดงผลออกทางหน้าจอได้ 4 ช่องทางดังนี้
การเขียนลงใน HTML Element โดยใช้ innerHTML
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>ทดสอบโปรแกรม</h1>
ผลลัพท์:
<p id="test"></p>
<script>
document.getElementById("test").innerHTML ='ผลบวก' + 100 + 50 + 9 ;
</script>
</body>
</html>
การเขียนลงใน HTML Element โดยใช้ document.write()
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>ทดสอบโปรแกรม</h1>
ผลลัพท์:
<p id="test"></p>
<script>
document.write(100 + 50 + 9) ;
</script>
</body>
</html>
การเขียนลงใน HTML Element โดยใช้ windows.alert()
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>ทดสอบโปรแกรม</h1>
<hr>
คำนวนค่า 100+50+9 = ?
<br>
<button type="button" onclick="window.alert(100+50+9)">ตอบ</button>
</body>
</html>
การเขียนลงใน HTML Element โดยใช้ console.log()
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>ทดสอบโปรแกรม</h1>
<script>
console.log(100 + 50 + 9) ;
</script>
</body>



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