gpt4 book ai didi

javascript - 在特定元素/类上使用 lastModified

转载 作者:行者123 更新时间:2023-11-30 19:44:28 26 4
gpt4 key购买 nike

我正在尝试使用 JavaScript lastModified能力;但不是在整个文档中(因为它似乎是为之设计的)。

  var x = new Date(document.lastModified);

我想用它来显示 lastModified 元素在指定类中的日期。

例如;我有一个类为“主页”的父 div 我想检测“主页”中的元素何时被 lastModified,然后显示日期。 但不包括常见的页眉/页脚;仅在指定类“主页

  • 也接受其他建议;目标是简单地输出一个更改/更新/修改特定元素后的日期。

最佳答案

我认为你能做的最好的就是......

$('.example-default-value').each(function() {
var default_value = this.value;
$(this).focus(function() {
if(this.value == default_value) {
this.value = '';
}
});
$(this).blur(function() {
if(this.value == '') {
this.value = default_value;
}
});
});
function example_append() {
$('#example').append($('#example-textarea').val());
$("#asd").html("This page was last modified on: "+document.lastModified);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="example" style="border: 1px solid rgb(204, 204, 204); margin: 5px 0pt; padding: 5px;">Example div</div>
<form>
<div><textarea class="example-default-value" id="example-textarea" style="width: 400px; height: 50px;">Type some text in here to be appended</textarea></div>
<div><input type="button" value="Append" onclick="example_append()" /></div>
</form>

<p id="asd"></p>

关于javascript - 在特定元素/类上使用 lastModified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55070204/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com