我正在尝试将包含版权的页脚中的 2011 年替换为当前年份。
目前我已成功将“2003-2011”替换为“2003-2012”,如下所示:
$(document).ready (function (function(){
$('div.footer').html($('div.footer').html() .replace('2003-2011','2003-2012'));
});
但我想将“2011”替换为当前年份,这样您就不必每年都更改脚本。
这样做是行不通的:
var year=getFullYear();
$(document).ready (function(){
$('div.footer').html($('div.footer').html() .replace('2011','year'));
});
一如既往,非常感谢您的帮助。
最佳答案
不要将年份
放在引号中,它是一个变量。将其放在引号中会生成字符串 'year'
。
var year = new Date().getFullYear(); // This should be `new Date`
// as `getFullYear` isn't a global function
$(document).ready (function(){
$('div.footer').html($('div.footer').html() .replace('2011', year));
});
关于javascript - 尝试用版权 div 中的 getFullYear 替换 2011,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8853887/