我已经检查了这段代码:https://stackoverflow.com/a/21337187/7425712并且效果很好,但我想如何在没有提交的情况下获得年龄。我只想要那个
<p>You are 29</p>
打印,没有别的。
function submitBday() {
var Q4A = "Your birthday is: ";
var Bdate = document.getElementById('bday').value;
var Bday = +new Date(Bdate);
Q4A += Bdate + ". You are " + ~~ ((Date.now() - Bday) / (31557600000));
var theBday = document.getElementById('resultBday');
theBday.innerHTML = Q4A;
}
我尝试过这样的事情,但我对js并不擅长。
var Bdate = new Date("01/30/1989");
谢谢! :)