extjs 年月日联动下拉框

TimePanel=Ext.extend(Ext.form.FormPanel,{
 constructor:function(){
  TimePanel.superclass.constructor.call(this,{
   border:false,
   defaults:{border:false},
   layout:'column',
   items:[{
    xtype:'combo',
    value:'2011',
    width:60,
    name:'yearcombo',
    store:new Ext.data.SimpleStore({
     fields:['year'],
     data:[['2010'],['2011'],['2012'],['2013']]
    }),
    listeners:{'select':this.changeDay},
    mode:'local',
    displayField:'year',
    valueField:'year',
    triggerAction:'all'
   },{
    xtype:'label',
    text:'年'
   },{
    xtype:'combo',
    value:'07',
    name:'monthcombo',
    width:50,
    store:new Ext.data.SimpleStore({
     fields:['month'],
     data:[['01'],['02'],['03'],['04'],['05'],['06'],['07'],['08'],['09'],['10'],['11'],['12']]
    }),
    listeners:{'select':this.changeDay},
    mode:'local',
    displayField:'month',
    valueField:'month',
    triggerAction:'all'
   },{
    xtype:'label',
    text:'月'
    
   },{
    xtype:'combo',
    value:'10',
    width:50,
    name:'daycombo',
    store:new Ext.data.SimpleStore({
     fields:['day'],
     data:[['01'],['02'],['03'],['04'],['05'],['06'],['07'],['08'],['09'],['10'],
       ['11'],['12'],['13'],['14'],['15'],['16'],['17'],['18'],['19'],['20'],
       ['21'],['22'],['23'],['24'],['25'],['26'],['27'],['28'],['29'],['30'],['31']]
    }),
    mode:'local',
    displayField:'day',
    valueField:'day',
    triggerAction:'all'
   },{
    xtype:'label',
    text:'日'
   }]
  });
 },
 /**
  * 年月变化,改变日
  */
 changeDay:function(){
  //每个月的初始天数  
                MonDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];  
  var year=this.ownerCt.findByType("combo")[0].getValue();
  var month=this.ownerCt.findByType("combo")[1].getValue();
  var n = MonDays[month - 1];  
  if(month=='2'&&isLeapYear(year)){
   n++;
  }
  
  var _store=new Ext.data.SimpleStore({
   fields:['day']
  });
  //填充日期下拉框
  for(var i=1; i<=n; i++)  
            {  
               var _record=new Ext.data.Record({'day':i});
      _store.add(_record);
            }
     this.ownerCt.findByType("combo")[2].store=_store;
     if(this.ownerCt.findByType("combo")[2].view)
      this.ownerCt.findByType("combo")[2].view.setStore(_store);  
 },
 /**
  * 判断是否闰年  
  * @param {} year
  * @return {}
  */
 isLeapYear:function (year)
    {   
          return( year%4==0 || (year%100 ==0 && year%400 == 0));  
    } 
});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值