国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Angularjs 手寫日歷的實現代碼(不用插件)

2019-11-19 15:09:00
字體:
來源:轉載
供稿:網友

本文介紹了Angularjs 手寫日歷的實現代碼(不用插件),分享給大家,具體如下:

效果:


Html:

<div class="plan_content_box" data-ng-init="showTime()">    <div class="field" style="width: 100%;">     <span class="field_label" style="width: 100%;text-align: center;">      <select id="time_year" ng-change="change_year(select_year)" ng-model="select_year" ng-options="x.id as x.value for x in all_year">       <!--<option value="1900">1900</option>-->      </select> 年      <select id="time_month" ng-change="change_month(select_month)" ng-model="select_month" ng-options="x.id as x.value for x in all_month">       </select> 月 {{active_day}} 日     </span>    </div>        <table class="table table-bordered hover_td" style="border: none;">     <tr id="float_td">      <td>星期日</td>      <td>星期一</td>      <td>星期二</td>      <td>星期三</td>      <td>星期四</td>      <td>星期五</td>      <td>星期六</td>      <td ng-repeat="day in days track by $index" ng-click="change_day(day)"        ng-class="{true:'active',false:''}[day==active_day]" ng-model="day">{{day}}</td>     </tr>    </table>   </div>

js:

 //  創建日歷    $scope.all_year = [];    $scope.all_month = [];  $scope.showTime = function() {   //在select中填入年份   for(var year = 2016; year < 2050; year++) {    var obj_1 = {'value': year, 'id': year}    $scope.all_year.push(obj_1);   }      //在select中填入月份   for(var month = 1; month < 13; month++) {    var obj_2 = {'value': month, 'id': month}    $scope.all_month.push(obj_2);   }   console.log($scope.all_year)   //初始化顯示 當前年和月   $scope.show_now()        }  //當select的選中的option發送變化的觸發的事件  $scope.change_year = function(data) {   $scope.showDays(data, $scope.select_month)  }  $scope.change_month = function(data) {   $scope.showDays($scope.select_year, data)     }  //返回指定的月份的天數 月份1-12  $scope.calDays = function (year, month) {   return new Date(year, month, 0).getDate();  }  $scope.days = [];  //展示指定的年和月的所有日期  $scope.showDays = function(year, month) {   $scope.days = [];      //得到表示指定年和月的1日的那個時間對象   var date = new Date(year, month - 1, 1);         //1.先添加響應的空白的li:這個月1號是星期幾,就添加幾個空白的li   var dayOfWeek = date.getDay(); //得到1日是星期幾   for(var i = 0; i < dayOfWeek; i++) {    $scope.days.push("");   }         //計算一個月有多少天   var daysOfMonth = $scope.calDays(year, month);   //2. 從1號開始添加li   for(var i = 1; i <= daysOfMonth; i++) {    $scope.days.push(i)   }  }    $scope.active_day = ''  $scope.select_year = ''  $scope.select_month = ''  //初始化顯示 當前年和月  $scope.show_now = function() {   var now = new Date();//   $("#time_year").val(now.getFullYear());//   $("#time_month").val(now.getMonth() + 1);    $scope.active_day = now.getDate();   $scope.select_year = now.getFullYear();   $scope.select_month = now.getMonth() + 1;   $scope.showDays($scope.select_year, $scope.select_month)  }        $scope.change_day = function(day){   $scope.active_day = ""   $scope.active_day = day  }  // 以上是創建日歷

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永新县| 镇雄县| 兴海县| 珠海市| 甘泉县| 天等县| 丹江口市| 木里| 临江市| 威宁| 沽源县| 宜兰县| 民权县| 平塘县| 鄄城县| 白朗县| 广西| 康平县| 鄂托克旗| 庆城县| 阜城县| 元谋县| 柳河县| 任丘市| 礼泉县| 郧西县| 自治县| 宜兰市| 论坛| 泸西县| 迁西县| 美姑县| 盈江县| 汶上县| 香港| 河西区| 卢氏县| 隆回县| 双城市| 西盟| 叶城县|