简体   繁体   English

如何在 HTML 中禁用日历

[英]How to disable calendar from been selected in HTML

I have an HTML <input /> with type=date and I'm trying to use javascript to disable an array of dates but for some reason, it is not working and not sure where I got it wrong, below is my code:我有一个 HTML <input /> type=date ,我正在尝试使用 javascript 禁用日期数组,但由于某种原因,它无法正常工作,并且不确定我哪里弄错了,下面是我的代码:

 var array = ["2022-08-25", "2022-08-22", "2022-08-21"] $('input[type="date"][name="tester"]').datepicker({ beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); return [array.indexOf(string) == -1] } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.13.1/jquery-ui.min.js" integrity="sha256-eTyxS0rkjpLEo16uXTS0uVCS4815lc40K2iVpWDvdSY=" crossorigin="anonymous"></script> <input type="date" name="tester">

Creating a datepicker on an <input type="date"> is not supported due to a UI conflict with the native picker.由于与本机选择器的 UI 冲突,不支持在<input type="date">上创建日期选择器。

See more: https://api.jqueryui.com/datepicker/查看更多: https://api.jqueryui.com/datepicker/

Consider the following.考虑以下。

 var array = ["2022-08-25", "2022-08-22", "2022-08-21"] $('input[name="tester"]').datepicker({ beforeShowDay: function(date) { var string = jQuery.datepicker.formatDate('yy-mm-dd', date); return [array.indexOf(string) === -1] } });
 <link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-3.6.0.js"></script> <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script> <input type="text" name="tester">

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

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