私は、ユーザーからの入力として生年月日がかかるテキストフィールドを持っています。別のテキストフィールドでは、年齢を計算したいと思っています。ただし、現在の日付と生年月日は異なる形式です。次のように出産のhtmlの形式が異なる日付の相違
現在の日付
日
年齢
はjavascript関数は次のとおりです。
年齢のテキストフィールドでfunction todayDate(){
var currentDate = new Date();
var day = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
document.getElementById("date").value = (day + "/" + month + "/" + year);
}
function ageCalculation(){
var currentDate = new Date();
var birthDate = document.getElementById("dob").value;
alert(birthDate);
var difference = currentDate - birthDate;
document.getElementById("age").value = difference ;
}
私は "NaNの"
これを確認してください:http://stackoverflow.com/a/21984136/2815635 – C2486
dob inはどのような形式ですか? –
それは素晴らしいです。だから何が問題なの? –