jquery-weui picker组件实现只选择年月

 

    var date = new Date()
      var month = date.getMonth()+1  //获取当前月份

      $('#selectTime').picker({
        toolbarTemplate:'<div class="toolbar"><div class="toolbar-inner"><a href="javascript:;" class="picker-button close-picker" style="color:#2F89FE;left: 0;right: auto;">取消</a><a href="javascript:;" class="picker-button close-picker" style="color:#2F89FE">完成</a></div></div>',
        cols:[
          {
            textAlign: 'left',
            values:(function () {//年份
        //从1970年开始到今年往后30年之间的范围
              for(var years = [],k=1970;k<=date.getFullYear()+30;k++){
                years.push(k)
              }
              return years
            })()
          },
          {
            textAlign: 'right',
            values:(function () {//月份
              return "01 02 03 04 05 06 07 08 09 10 11 12".split(" ")
            })()
          }
        ],
        value:[date.getFullYear(),month<10?'0'+month:month],
        //改变时触发
        onChange:function (re,val,displayValue) {
          // val当前选择的值,displayValue当前显示的值
        },
        //关闭时触发
        onClose:function (e) {
          console.log(e)
        }
      });

 

posted @ 2019-05-08 17:01  怨灵骑士  阅读(3340)  评论(0编辑  收藏  举报