簡體   English   中英

如何使用 HTML5 datetime-local 輸入禁用上一個日期?

[英]How to disable previous date using HTML5 datetime-local input?

我只是想阻止用戶在 input datetime-local中輸入或禁用以前的日期,有沒有辦法做到這一點?

這是我所做的,不幸的是,這段代碼沒有任何反應:

 <input type="datetime-local" class="form-control col-md-6" name="book" required> <script> var today = new Date().toISOString().split('T')[0]; document.getElementsByName('book')[0].setAttribute('min', today); </script>

嘗試這個

 var today = new Date().toISOString().slice(0, 16); document.getElementsByName("book")[0].min = today;
 <input type="datetime-local" class="form-control col-md-6" name="book" required>

        <div class="row">
            <div class="col-md-6">
              <label for="time_start">{{ __('adminstaticword.timestart') }}:<sup class="redstar">*</sup></label>
              <input type="datetime-local" class="form-control" name="time_start" id="time_start" placeholder="Enter time_start" required min="{{date('Y-m-d')}}"  value="{{ old('time_start') }}" >
              <script>
                var today = new Date().toISOString().slice(0, 16);
                document.getElementsByName("time_start")[0].min = today;
                </script>
            </div>   

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM