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

คุณสมบัติ cite ของ Blockquote ใน HTML DOM

คุณสมบัติ cite ของ Blockquote

คุณสมบัติ cite ของ <blockquote> ใช้สำหรับตั้งค่าหรือคืนค่าแอตทริบิวต์ cite ของคำพูด คุณสมบัตินี้มีประโยชน์สำหรับ screen readers และ search engines ไม่มีผลทางสายตาต่อหน้าเว็บปกติ ใช้ระบุ URL แหล่งที่มาของคำพูด

ไวยากรณ์ (Syntax)

การกำหนดค่า cite

blockquoteObject.cite = URL

พารามิเตอร์: URL - ระบุตำแหน่งของการอ้างอิง

ตัวอย่างการใช้งาน

ตัวอย่างด้านล่างแสดงการเปลี่ยนค่า cite attribute ของ blockquote

<!DOCTYPE html>
<html>
<body>
    <h2>Quote</h2>
    <p>Here is a quote:</p>
    <blockquote id="myBlockquote" cite="www.webexample.com">
        Here is some sample text in place of quote.
    </blockquote>
    <p>Click the button below to change the above quote cite value.</p>
    <button onclick="citeChange()">CHANGE</button>
    <p id="Sample"></p>
    <script>
        function citeChange() {
            document.getElementById("myBlockquote").cite = "https://www.examplesite.com";
            document.getElementById("Sample").innerHTML = "The value of the cite attribute was changed to 'www.examplesite.com'";
        }
    </script>
</body>
</html>

ผลลัพธ์

เริ่มต้น: blockquote มี cite="www.webexample.com"

คลิก CHANGE: cite เปลี่ยนเป็น "https://www.examplesite.com" และแสดงข้อความยืนยัน

คำอธิบายเพิ่มเติม

  • คุณสมบัติ cite ไม่ส่งผลต่อการแสดงผลทางสายตา (no visual effect)
  • มีค่าสำหรับ: accessibility (screen readers), SEO, semantic meaning
  • ควรใช้ URL เต็มรูปแบบ (absolute URL) รวม protocol (https:// หรือ https://)
  • ต่างจากอิลิเมนต์ <cite> ที่ใช้แสดงชื่องาน/ผู้เขียนบนหน้าจอ
  • สามารถใช้กับ <q> (inline quotation) และ <del>, <ins> ได้เช่นกัน
  • เข้าถึงได้ผ่าน CSS attribute selector: blockquote[cite]