與 HTML <del> 元素關聯的 HTML DOM del dateTime 屬性用於告訴用戶網站上的某些文本何時被刪除。它告訴文本被刪除的日期和時間。
用法
以下是語法 -
設置 dateTime 屬性 -
delObject.dateTime = YYYY -MM-DDThh:mm:ssTZD
這裏, YYYY=years , MM=months , DD=days, T=separator or a space, hh=hours , mm=minutes,ss=seconds, TZD=Time zone designator
示例
讓我們看一個 del dateTime 屬性的例子 -
<!DOCTYPE html>
<html>
<head>
<title>del dateTime property example</title>
<style>
#Sample{color:blue};
</style>
</head>
<body>
<h2>del dateTime property example</h2>
<p><del id="Del1" datetime="2019-02-22T05:10:22Z">Some text has been deleted</del></p>
<p>Click the below button to change the datetime attribute value of the deleted text above</p>
<button onclick="changeDate()">CHANGE</button>
<p id="Sample"></p>
<script>
function changeDate() {
document.getElementById("Del1").dateTime = "2019-06-27T10:20:02Z";
document.getElementById("Sample").innerHTML = "The datetime attribute attribute was changed to '2019-06-27T10:20:02Z'.";
}
</script>
</body>
</html>
輸出
這將產生以下輸出 -
單擊更改按鈕 -
在上麵的例子中 -
我們首先在 <p> 元素中創建了一個 <del> 元素,其 ID 為 “Del1”,日期時間屬性值為 “2019-02-22T05:10:22Z”。
<p><del id="Del1" datetime="2019-02-22T05:10:22Z">Some text has been deleted</del></p>
然後,我們創建了按鈕 CHANGE,當用戶單擊該按鈕時將執行 changeDate() 方法 -
<button onclick="changeDate()">CHANGE</button>
changeDate() 方法獲取 <del> 元素並將其 dateTime 屬性值設置為 “2019-06-27T10:20:02Z”。然後,我們在 ID 為 “Sample” 的段落中顯示此更改,並將其 innerHTML 屬性設置為我們要顯示的文本。段落 “Sample” 內的文本以藍色顯示,因為它具有與其應用的 id 對應的樣式 -
function changeDate() { document.getElementById("Del1").dateTime = "2019-06-27T10:20:02Z"; document.getElementById("Sample").innerHTML = "The datetime attribute attribute was changed to '2019-06-27T10:20:02Z'."; }
相關用法
- HTML DOM del cite屬性用法及代碼示例
- HTML DOM deleteFromDocument()用法及代碼示例
- HTML DOM document contentType屬性用法及代碼示例
- HTML DOM document scrollingElement屬性用法及代碼示例
- HTML DOM dl用法及代碼示例
- HTML DOM document visibilityState屬性用法及代碼示例
- HTML DOM document location屬性用法及代碼示例
- HTML DOM document plugins屬性用法及代碼示例
- HTML DOM div用法及代碼示例
- HTML DOM Style overflowY屬性用法及代碼示例
- HTML DOM Document hidden屬性用法及代碼示例
- HTML DOM IFrame用法及代碼示例
- HTML DOM Textarea cols屬性用法及代碼示例
- HTML DOM Style pageBreakAfter屬性用法及代碼示例
- HTML DOM Base href屬性用法及代碼示例
- HTML DOM Pre用法及代碼示例
- HTML DOM Input Month用法及代碼示例
- HTML DOM Video canPlayType()用法及代碼示例
- HTML DOM Range deleteContents()用法及代碼示例
- HTML DOM console.dirxml()用法及代碼示例
注:本文由純淨天空篩選整理自AmitDiwan大神的英文原創作品 HTML DOM del dateTime Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。