HTML DOM ins dateTime 属性
htmlweb developmentfront end technology更新于 2025/9/14 1:16:17
HTML DOM ins dateTime 属性返回文本插入的日期和时间。
语法
以下是语法 −
返回字符串值
insObject.dateTime
示例
让我们看一个 ins dateTime 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<title>ins dateTime</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>ins-dateTime</legend>
<h1>Fact:</h1>
<p>Water cannot persist on moon's surface.
<ins id="newInfo" cite="https://www.example.com/water-ice-moon-surface-confirmed.html" datetime="2018-08-21T18:23Z">
Water ice found on moon.</ins>
</p>
<input type="button" onclick="getDate()" value="When was this change made?">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var insDateTime = document.getElementById("newInfo");
function getDate() {
divDisplay.textContent = 'Text inserted on '+insDateTime.dateTime.split("T")[0];
divDisplay.textContent += ' at '+insDateTime.dateTime.split("T")[1];
}
</script>
</body>
</html>
输出
这将产生以下输出 −
点击"此更改是何时进行的?"按钮之前 −

点击"此更改是何时进行的?"按钮之后 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

