gpt4 book ai didi

javascript - 将变量插入 .append html

转载 作者:行者123 更新时间:2023-12-03 09:27:14 28 4
gpt4 key购买 nike

我正在尝试插入日期和时间(以我在 console.log 中工作的方式)。本质上,我有一个论坛,当用户对帖子发表评论并单击评论按钮时,它会将他或她输入到评论部分的文本上传。这工作正常,但我希望它也插入当前日期和时间。截至目前,我只有一个静态日期和时间。

我尝试使用:document.write(dateNTime)

var t = new Date()

var DateNTime = (t.toDateString() + ", at " + t.getHours() + ":" +
t.getMinutes())
console.log(DateNTime)

$('#commentButton').on('click', function() {
if($('#forumCommentSearchBox').val() ) {

$('.commentList').append('<li> <div class="commenterImage"> \
<img
src="http://lorempixel.com/50/50/people/9"> \
</div> \
<div class="commentText"> \
<p \
class="">'+$('#forumCommentSearchBox').val()+'</p> \
<span class="date sub-text">on March 5th,
2014</span> \
</div></li>');


}
else{
alert("idiot");
}
});

最佳答案

如果我理解正确的话...

var t = new Date()

var DateNTime = (t.toDateString() + ", at " + t.getHours() + ":" +
t.getMinutes())

$('#commentButton').on('click', function() {
if($('#forumCommentSearchBox').val() ) {

$('.commentList').append('<li> <div class="commenterImage"> \
<img src="http://lorempixel.com/50/50/people/9"> \
</div> \
<div class="commentText"> \
<p class="">'+$('#forumCommentSearchBox').val()+'</p> \
<span class="date sub-text">on ' + DateNTime + '</span> \
</div></li>');

}
else{
alert("idiot");
}
});

关于javascript - 将变量插入 .append html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31632321/

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