我想使用 PHP 和 mysql 禁用 html 日期选择器(输入类型=“日期”)的某些未来日期

我想input type="date"使用 PHP 和 MySQL 禁用 HTML 日期选择器 ( ) 的某些未来日期。

有人可以帮我做到这一点吗?我试图做到这一点,并通过 Google 搜索,但没有找到使用 PHP 和 MySQL 禁用某些日期的方法。


慕标琳琳
浏览 105回答 1
1回答

牛魔王的故事

这是一个演示。这使用 Bootstrap datepicker 和 jquery。另外,我在代码内的注释中提到了在哪里使用 php<!DOCTYPE html><html><head>&nbsp; &nbsp; <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.css">&nbsp; &nbsp; <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.css">&nbsp; &nbsp; <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>&nbsp; &nbsp; <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.js"></script>&nbsp; &nbsp; <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script></head><body>&nbsp; &nbsp;<div class="container">&nbsp; &nbsp; <input type="text" name="date" class="form-control datepicker" autocomplete="off"></div>&nbsp; &nbsp;</body>&nbsp;&nbsp;<script type="text/javascript">&nbsp; &nbsp; // This can come from php&nbsp; &nbsp; // var disableDates = [<?php //echo $your_variables_from_php_mysql_printed_in_the_format_below; ?>]&nbsp; &nbsp; var disableDates = ["7-7-2020", "14-7-2020", "15-7-2020","27-7-2020"];&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; $('.datepicker').datepicker({&nbsp; &nbsp; &nbsp; &nbsp; format: 'mm/dd/yyyy',&nbsp; &nbsp; &nbsp; &nbsp; beforeShowDay: function(date){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(disableDates.indexOf(dmy) != -1){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });</script></html>
打开App,查看更多内容
随时随地看视频慕课网APP