附加的innerhtml

时间:2015-03-31 16:17:34

标签: javascript jquery html

我正在尝试使用当前日期时间更改表格单元格,但我似乎无法弄明白。

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

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

function currentDateNow(){
    var newDate = new Date();
    return newDate;
}

任何帮助将不胜感激。谢谢!

2 个答案:

答案 0 :(得分:1)

你准备好的功能稍微偏离,应该是:

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

答案 1 :(得分:1)

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

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

function currentDateNow(){
    var newDate = new Date();
    return newDate;
}

Thus, surround the code in an unnamed function, and it will work.

DEMO

相关问题