angular 设置年份选择下拉框,并默认今年
程序员文章站
2022-07-03 09:28:37
$scope.yearList = [ {k : "2014", v : "2014"}, {k : "2015", v : "2015"}, {k : "2016", v : "2016"}, {k : "2017", v : "2017"}, ... ......
<select ng-model="selectedYear" ng-change="yearChange(selectedYear)"> <option ng-repeat="x in yearList" value="{{x.k}}">{{x.v}</option> </select>
$scope.yearList = [ {k : "2014", v : "2014"}, {k : "2015", v : "2015"}, {k : "2016", v : "2016"}, {k : "2017", v : "2017"}, {k : "2018", v : "2018"}, {k : "2019", v : "2019"}, {k : "2020", v : "2020"}, {k : "2021", v : "2021"}, {k : "2022", v : "2022"}, {k : "2023", v : "2023"} ];
// 默认为今年 var date = new Date; $scope.selectedYear = date.getFullYear(); $scope.year = $scope.selectedYear; $scope.yearChange = function(v){ $scope.year = v; };