ข้อกำหนด: ปุ่มคลิกเพื่อรับเนื้อหาที่เลือกในกล่องอินพุตเพื่อให้เนื้อหาที่เลือกเปลี่ยนเป็นสีแดง
การใช้งาน: รหัสมีดังนี้
<! doctype html> <html> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"> <title> ทดสอบ </title> <style type = "text/css"> div {display:} type = "button" value = "รับค่าในกล่องข้อความ" id = "btn" onclick = "getText ();"/> <div id = "showtext"> </div> <script type = "text/javascript"> function getText () {var showtext = document.getElementById ("showtext" "red"; showtext.innerhtml = document.getElementById ("txt"). value;} </script> </body> </html>ผล: