jquery based on Muipicker to implement the iOS time selection _jquery

Source: Internet
Author: User

First let's look at the original Muipicker example

<! DOCTYPE html>  

On this basis, modified to a plug-in similar to the iOS selection time.

It's OK to change the data into the following data.

(Function ($, doc) {$.init ();
      $.ready (function () {//Normal example/month var yeararray = new Array ();
        for (var i = 0; i < i + +) {var montharray = new Array ();
          for (var j = 0; J < J + +) {var month = new Object ();
          Month.value = j + 1 + "month";
          Month.text = j + 1 + "month";
        Montharray.push (month);
        var year = new Object ();
        Year.value = i + 2016 + "year";
        Year.text = i + 2016 + "year";
        Year.children = Montharray;
      Yeararray.push (year);

};
      Month-day var yeararray = new Array ();
        for (var i = 0; i < i + +) {var montharray = new Array ();
          for (var j = 0; J < J + +) {//The last day of the month var year = i + 2016;
          var month = j;
          var lastday = new Date (year, month + 1, 0). GetDate ();//month to add 1, originally month started from 0, but because 0 is this month's last month, so until last month. if (year = = 2016 && month = 1) {CONSOLE.LOG ("lastday" + lastday);
          var dayarray = new Array ();
            for (var k = 0; k < lastday K + +) {var day = new Object ();
            Day.value = k + 1 + "Day";
            Day.text = k + 1 + "Day";
          Dayarray.push (day);
          var month = new Object ();
          Month.children = Dayarray;
          Month.value = j + 1 + "month";
          Month.text = j + 1 + "month";
        Montharray.push (month);
        var year = new Object ();
        Year.value = i + 2016 + "year";
        Year.text = i + 2016 + "year";
        Year.children = Montharray;
      Yeararray.push (year);
      };

Console.log (Yeararray);
      Hour minute var hoursec = new Array ();
        for (var i = 0; i < i + +) {var hschildrenarray = new Array ();
          for (var j = 0; J < J + +) {var childrenobject = new Object ();
          var sectrue = j;
            if (J < ten) {var sectrue = j; ChildRenobject.value = "0" + sectrue;
          Childrenobject.text = "0" + sectrue;
            }else {childrenobject.value = sectrue;
          Childrenobject.text = Sectrue;
        } hschildrenarray.push (Childrenobject);
        The var object = new Object ();
          if (I < ten) {Object.value = "0" + i + ":";
        Object.text = "0" + i + ":";
          }else {object.value = i + ":";
        Object.text = i + ":";
        } Object.children = Hschildrenarray;
      Hoursec.push (object);
    };
  });

 }) (MUI, document);

Effect Chart:

Month Day

Hour minutes

The effect can only be seen in mobile phone or chrome mobile phone simulator.

Finally, attach the Muipicker github address Https://github.com/dcloudio/mui/tree/master/examples/hello-mui

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.