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

How to create a speed 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>Speed Converter</h1> <h2>Type speed in Kilometer per hour to convert it into meter per hour</h2> <p> <label>Kilometer Per Hour</label> <input id="inputKm" type="number" placeholder="KilometersPerHour" oninput="KmphtoMphConverter(this.value)" onchange="KmphtoMphConverter(this.value)"/> </p> <p>Meters Per second: <span class="metersPerSecond"></span></p> <script>    function KmphtoMphConverter(speed) {       document.querySelector(".metersPerSecond").innerHTML = speed * 0.277778;    } </script> </body> </html>

ผลลัพธ์

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

How to create a speed converter with HTML and JavaScript?

เมื่อกรอกความเร็วใน kph -

How to create a speed converter with HTML and JavaScript?