gpt4 book ai didi

javascript - 选择后显示日期时间

转载 作者:行者123 更新时间:2023-12-02 22:17:16 25 4
gpt4 key购买 nike

我使用 XDSoft 日期时间选择器作为内联

<form id="dateForm" action="" method="post">

<div id="test">
{{ form }}
</div>
<script>
$(function ()
{
$("#id_scheduled_time").datetimepicker
({
format: 'd - m - Y H:i',
inline:true,
...
});
});
</script>
</form>

如何在日历旁边显示所选的日期时间值?

我已经尝试过这个:

var logic = function( currentDateTime )
{
div = document.getElementById( 'test' )
div.insertAdjacentHTML( 'beforeend', currentDateTime );
};

但日历旁边没有显示任何内容。

这有效,但我不想使用警报:

var logic = function( currentDateTime )
{
alert( currentDateTime );
};

最佳答案

我知道您需要在带有 id 测试的 div 之后放置一个以所选日期作为文本内容的新元素。如果是这样,您可以尝试以下方法

function logic(currentDateTime) {
const test = document.querySelector("div#test");
let span = test.nextElementSibling;

if (span.nodeName === "SPAN" && span.textContent.trim() === currentDateTime)
return;

if (span.nodeName === "SPAN" && span.textContent.trim() !== currentDateTime) {
span.textContent = currentDateTime;

return;
}

const node = document.createElement("span");

node.textContent = currentDateTime;

test.parentNode.insertBefore(node, test.nextSibling);
}

关于javascript - 选择后显示日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59345764/

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