简体   繁体   English

如何添加物化日期选择器

[英]How to add materialize Date picker

I am new to front-end development, I am trying to add a date picker ( Materialize framework ).我是前端开发的新手,我正在尝试添加一个日期选择器( Materialize 框架)。 I spent a lot of time searching the internet for我花了很多时间在互联网上搜索

"how to add materialize date picker". “如何添加具体化日期选择器”。

But I couldn't find the solution to my problem.但是我找不到解决我的问题的方法。

<html>
  <head>
  <!--Import Google Icon Font-->
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <!--Import materialize.css-->
  <link rel="stylesheet" 
href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-
beta/css/materialize.min.css">

  <!--Let browser know website is optimized for mobile-->
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>

<body>

<input type="text" class="datepicker">
  <!--JavaScript at end of body for optimized loading-->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script>
  <script
 src="http://code.jquery.com/jquery-3.3.1.js"
 integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
 crossorigin="anonymous"></script>
 <script>
  document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.datepicker');
var instances = M.Datepicker.init(elems, options);
 });

 // Or with jQuery

  $(document).ready(function(){
   $('.datepicker').datepicker();
  });
 </script>
   </body>
 </html>

Using the documentation instructions :使用文档说明

 // Using with jQuery $(document).ready(function(){ $('.datepicker').datepicker(); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> =<!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css"> <!-- Compiled and minified JavaScript --> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/js/materialize.min.js"></script> <body> <input type="text" class="datepicker"> </body>

Note笔记

I just suggest you first import jquery in your HTML and then materiliaze.js as shown above我只是建议您首先在 HTML 中导入jquery然后如上所示导入materiliaze.js

Use this theme as your base theme, Most of component are there with materialize touch.使用这个主题作为你的基本主题,大部分组件都带有实体化触摸。 https://materializecss.com/pickers.html https://materializecss.com/pickers.html

Check the demo they have.检查他们的演示。

Here's your problem.这是你的问题。

<input type="text" class="datepicker">

Change the input type to "date".将输入类型更改为“日期”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM