基于angular实现三级联动的生日插件
写了一个生日联动插件具体的效果是这样的:
具体的数据
我取得数据是今年的数据,如果是想要做三级联动的日期插件,改一下时间就好了
varapp=angular.module("dataPicker",[])
app.factory('dataPicker',['$http','$q',function($http,$q){ return{ query:function(){ varlengthYear=100; vardataPicker={ month:[], year:[], day:[] }; vardata=newDate(); varnowyear=data.getFullYear(); for(vari=nowyear,j=0;i>nowyear-lengthYear;i--,j++){ dataPicker.year[j]=i; } for(vari=0;i<=11;i++){ if(i<9){ dataPicker.month[i]='0'+(i+1); }else{ dataPicker.month[i]=String(i+1); } } returndataPicker; } } }])
directive插件的主要内容
app.directive('selectDatepicker',function($http,dataPicker){ return{ restrict:'EAMC', replace:false, scope:{ birthday:'=birthday' }, transclude:true, template:'生日'+ '{{x}}'+ ' {{x}}'+ ' {{x}}', link:function(scope,element){ vararr=[]; scope.birthday=scope.birthday=='0000-00-00'?"":scope.birthday varshuju=dataPicker.query() scope.yearAll=shuju.year; scope.MonthAll=shuju.month; if(scope.birthday){ scope.birY=scope.birthday.birthday.split('-')[0]; scope.birM=String(scope.birthday.birthday.split('-')[1]) }else{ scope.birY=""; scope.birM=""; } scope.getDaysInOneMonth=function(year,month){ varmonth1=Number(month); month1=parseInt(month1,10) vard=newDate(Number(year),month1,0); returnd.getDate(); } scope.getDayArr=function(day){ shuju.day=[]; for(vari=0;i html
js传入的数据
$scope.birthday={ birthday:1993-01-20, returnValue:'', }以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。