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

栾英资
2023-12-01

 

    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)
        }
      });

 

转载于:https://www.cnblogs.com/ylqs/p/10832177.html

 类似资料: