<! doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <title> } </style> <script type = "text/javascript">/** วาดจุด*/ฟังก์ชั่น makedot (x, y) {pointdiv = "<div style = 'ความสูง: 1px; ตำแหน่ง: Absolute; ซ้าย:" + x + "px; top:" + y + "px; width: 1px; Return PointDiv;} /** วาดเส้นตรงตามพิกัดของสองจุด */ ฟังก์ชันบรรทัด (x1, y1, x2, y2) {var slope; // ความลาดชัน var direction; // ประสานงานการเคลื่อนไหว var tx = x2 - x1; var ty = y2 - y1; if (tx == 0 && ty == 0) return; var points = ""; แกน var; // พิกัดบนแกนถ้า (math.abs (tx)> = math.abs (ty)) {// ย้ายทิศทาง = tx> 0? 1: -1; tx = math.abs (tx); ความชัน = ty / tx; แกน = x1; สำหรับ (i = 0; i <tx; i ++) {คะแนน += makedot (แกน, y1 +i * ความชัน); แกน += ทิศทาง; }} else {// ย้ายทิศทางในทิศทาง y-axis = ty> 0? 1: -1; ty = math.abs (ty); ความชัน = tx / ty; แกน = y1; สำหรับ (i = 0; i <ty; i ++) {คะแนน += makedot (x1 +i * ความชัน, แกน); แกน += ทิศทาง; }} var container = document.getElementById ("container"); container.innerhtml += คะแนน; } var oldpoint = null; // รับฟังก์ชันตำแหน่งเมาส์ mouseposition (ev) {ev = ev || window.event; if (ev.pagex || ev.pagey) {return {x: ev.pagex, y: ev.pagey}; } var doc = document.documentelement, body = document.body; var pagex = event.clientx + (doc && doc.scrollleft || body && body.scrollleft || 0) - (doc && doc.clientleft || body && body.clientleft || 0); var pagey = event.clienty + (doc && doc.scrolltop || body && body.scrolltop || 0) - (doc && doc.clienttop || body && body.clienttop || 0); return {x: pagex, y: pagey};} function recordpoint (ev) {var point = mouseposition (ev); if (oldpoint! = null) {line (oldpoint.x, oldpoint.y, point.x, point.y); } oldpoint = point;} </script> </head> <body> <div id = "container" onclick = "recordpoint (เหตุการณ์);"> </div> <script type = "text/javascript"> // line (19,19,22,300); </script> </body> </html>