Appending the innerhtml of <th>

Appending the innerhtml of <th>

本文关键字:th gt the lt of Appending innerhtml      更新时间:2023-09-26

我试图用当前日期时间更改一个表单元格,但似乎无法解决。

以下是示例:http://jsfiddle.net/mkjckt3b/

 $(document).ready(
  $("#date").html("Date of Report: " + currentDateNow());
 );
function currentDateNow(){
    var newDate = new Date();
    return newDate;
}

如有任何帮助,我们将不胜感激。非常感谢。

您的就绪功能有点不正常,应该是:

$(document).ready(function(){
  $("#date").html("Date of Report: " + currentDateNow());
});

您不能调用.ready()中的一行代码,您需要传入一个函数:

$(document).ready(function(){
  $("#date").html("Date of Report: " + currentDateNow());
});
function currentDateNow(){
    var newDate = new Date();
    return newDate;
}

因此,将代码包围在一个未命名的函数中,它就会起作用

DEMO