HTML DOM del dateTime 屬性
HTML DOM del dateTime 屬性與 HTML <del> 元素相關聯,用於告知使用者網站上的某些文字已刪除。它告訴文字被刪除的日期和時間。
語法
以下為此處的語法 −
設定 dateTime 屬性 −
delObject.dateTime = YYYY -MM-DDThh:mm:ssTZD
在此處,YYYY=年數,MM=月份,DD=天數,T=分隔符或空格,hh=小時數,mm=分鐘數,ss=秒數,TZD=時區識別符號
示例
我們來看一個關於 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>輸出
它將生成以下輸出 −

單擊 CHANGE 按鈕 −

在上述示例中 −
我們首先在具有 id “Del1” 和 dateTime 屬性值“2019-02-22T05:10:22Z” 的 <p> 元素內建立了一個 <del> 元素。
<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'.";
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP