关于JavaScript语法的问题

时间:2010-06-08 07:18:37

标签: javascript jquery

$(document).ready(function(){

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    var month = new array("January","February","March","April","May","June","July","August","September","October","November","December");

    var mon;
    mon = month(m);

    var today = m+"/"+d+"/"+y
    $('#calendar').append('<div id="today">Today is'+' '+mon+'/'+d+'/'+y+'.');

});

2 个答案:

答案 0 :(得分:4)

而不是mon = month(m);使用方括号表示法:mon = month[m];new array()应该是new Array()或更好,请使用数组文字,例如['First','Second','Third']

$(document).ready(function(){

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    var month = ["January","February","March","April","May","June","July","August","September","October","November","December"];

    var mon;
    mon = month[m];

    var today = m+"/"+d+"/"+y
    $('#calendar').append('<div id="today">Today is'+' '+mon+'/'+d+'/'+y+'.');

});

答案 1 :(得分:0)

您似乎没有关闭<div id="today">标记。将</div>添加到您的代码中。

像这样:

$('#calendar').append('<div id="today">Today is'+' '+mon+'/'+d+'/'+y+'.'+'</div>');