我沒有任何代碼從您根據回答過的,但在這裏是爲了幫助您找到正確年齡的關係:
$scope.dateDiff = function(birthMonth, birthDay, birthYear) {
var todayDate = new Date(),
todayYear = todayDate.getFullYear(),
todayMonth = todayDate.getMonth(),
todayDay = todayDate.getDate(),
age = todayYear - birthYear;
if (todayMonth < birthMonth - 1)
{
age--;
}
if (birthMonth - 1 === todayMonth && todayDay < birthDay)
{
age--;
}
return age;
};
$scope.dateDiff(8,15,1963); // return as 50 as birthday has passed
$scope.dateDiff(9,15,1963); // return as 49 as birthday has not yet happened
在你的HTML,你可以使用ng-options
允許用戶從下拉列表中選擇日期。
Day <select ng-model="selectedDay" ng-options="day as day.date for day in days"></select>
Here is a full working example。
因爲您是Angular的新手,請務必花時間瞭解此代碼的工作原理。起初,ng-options
看起來有點混亂,但是當你開始理解Angular Principles時,它不應該是一個問題。
顯示你有什麼代碼 –