HTML DOM del cite 屬性
與 HTML <del> 元素關聯的 HTML DOM del cite 屬性用於告知使用者網站上的某些文字為何被刪除。為此,它指定了說明為何刪除給定文字的 URL。
del cite 屬性提高了網站的可訪問性,因為它沒有視覺提示,但可以幫助螢幕閱讀器。del cite 屬性設定或返回 HTML <del> 元素的 cite 特性的值。
語法
以下是語法 −
設定 cite 屬性 −
delObject.cite = URL
此處,URL 指定宣告為何刪除文字的文件的 URL。URL 可以是相對的,也可以是絕對的。
示例
讓我們看一個 HTML DOM del cite 屬性的示例 −
<!DOCTYPE html> <html> <head> <title>Del cite</title> <style> #Sample{color:blue}; </style> </head> <body> <h2>del cite property example</h2> <p><del id="Del1" cite="sampleDeleted.html">Some text has been deleted</del></p> <p>Click the below button to change the cite attribute value of the above deleted text</p> <button onclick="citeChange()">Change Cite</button> <p id="Sample"></p> <script> function citeChange() { document.getElementById("Del1").cite = "https://example.com/deletedText.html"; document.getElementById("Sample").innerHTML = "The del cite attribute value was changed to 'https://example.com/deletedText.html'."; } </script> </body> </html>
輸出
這將產生以下輸出 −
在單擊更改引用按鈕時 −
在上面的示例中 −
我們首先在關聯了 id “Del1” 的 <p> 元素內建立 <del> 元素,並且 del 元素的 cite 特性值為 “sampleDeleted.html”。
<p><del id="Del1" cite="sampleDeleted.html">Some text has been deleted</del></p>
然後,我們建立了一個 “更改引用” 按鈕,當用戶單擊時該按鈕將執行 citeChange() 方法 −
<button onclick="citeChange()">Change Cite</button>
citeChange() 方法使用 getElementById() 方法獲取 <del> 元素並將其 cite 屬性值更改為 “https://example.com/deletedText.html” 。然後我們使用段落元素的 innerHTML 屬性在 id 為 “Sample” 的段落中顯示此更改。由於我們已應用與其 id 相對應的樣式,因此 “Sample” 段落內的文字顯示為藍色 −
function citeChange() { document.getElementById("Del1").cite = "https://example.com/deletedText.html"; document.getElementById("Sample").innerHTML = "The del cite attribute value was changed to 'https://example.com/deletedText.html'."; }
廣告