Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

How to create a temperature converter with HTML and JavaScript?


เพื่อสร้างเครื่องมือแปลงอุณหภูมิด้วย HTML และ JavaScript โค้ดมีดังนี้

ตัวอย่าง

<!DOCTYPE html> <html> <head> <style>    body{       font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;    }    input,span{       font-size: 20px;    } </style> </head> <body> <h1>Temperature Converter</h1> <h2>Type Temperature in celcius to convert it into fahrenheit</h2> <p> <label>Celcius</label> <input id="inputKG" type="number" placeholder="Celcius" oninput="CtoFConverter(this.value)" onchange="CtoFConverter(this.value)"> </p> <p>Fahrenheit: <span class="fahrenheit"></span></p> <script>    function CtoFConverter(temp) {       document.querySelector(".fahrenheit").innerHTML=(temp-32)/1.8;    } </script> </body> </html>

ผลลัพธ์

โค้ดข้างต้นจะสร้างผลลัพธ์ดังนี้ -

How to create a temperature converter with HTML and JavaScript?

เมื่อกรอกอุณหภูมิเป็นเซลเซียส -

How to create a temperature converter with HTML and JavaScript?