มีหลายวิธีในการเรียกดูรูปภาพในหน้าต่างเดียวกัน ในตัวอย่างนี้ฉันต้องการแนะนำให้คุณใช้ JS เพื่อรับแอตทริบิวต์ SRC ของ IMG และแทนที่ เพื่อนที่ต้องการสิ่งนี้สามารถอ้างถึงมันได้
<! doctype html public "-// w3c // dtd html 4.01 transitional // en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <title> แทรกชื่อเรื่องที่นี่ </title> <style> H1 {ตำแหน่ง: Absolute; margin-left: 150px;} ul {ตำแหน่ง: Absolute; margin-top: 50px; margin-left: 80px;} li {float: left; list-style: ไม่มี; IMG {ตำแหน่ง: Absolute; margin-top: 100px; margin-left: 100px; ความกว้าง: 1000px; ความสูง: 600px;} p {ตำแหน่ง: สัมบูรณ์ var oimg = document.getElementById ("IMG1"); oimg.setAttribute ("SRC", OSRC); var op = document.getElementById ("P1"); var otxt = a.getAttribute ("title"); op.childnodes [0] .nodevalue = otxt ;; } </script> </head> <body> <h1> cat home </h1> <ul> <li> <a href = "img/1.jpg" onclick = "showcat (this); return false;"> แมวขาว </a> </li> <li> <li> <a href = "img/3.jpg" onclick = "showcat (this); return false;"> cat cat </a> </li></ul> <img id = "img1" src = "img/4.jpg"/> <p id = "p1"> เลือกแมว </