我如何在输入类型上激活日期选择器=日期我使用Laravel& JavaScript?
我将Laravel 9与Bootstrap 5一起使用,
我有以下输入:
当前,当我单击日期输入日期时,datepicker会弹出,但当我选中输入时却没有。
这是我的一些HTML代码:
{{-- Name --}}
<div class="input-group mb-4">
<input wire:model="addName" class="form-control border-0 fs-14" placeholder="Name" aria-label="Name" type="text" name="name" required autofocus>
</div>
{{-- Surname --}}
<div class="input-group mb-4">
<input wire:model="addSurname" class="form-control border-0 fs-14" placeholder="Surname" aria-label="Surname" type="text" name="surname" required>
</div>
{{-- Date of Birth --}}
<div class="input-group mb-4">
<input id="DOB" wire:model="dateOfBirth" class="form-control border-0 fs-14" placeholder="Date of Birth" aria-label="Date" aria-describedby="email-icon" type="text" max="9999-12-31" onfocus="(this.type='date')" onblur="(this.type='text')" name="date_of_birth" required>
</div>
{{-- Email --}}
<div class="input-group mb-4">
<input wire:model="addEmail" class="form-control border-0 fs-14" placeholder="Email" aria-label="Email" type="email" name="email" required>
</div>
@if ($this->userExistsAlready === true)
<span class="ms-1 ps-2 mb-3 fs-13 fw-600 text-danger">Email already taken</span>
@endif
{{-- Instagram --}}
<div class="input-group mb-4">
<input wire:model="addInstagram" class="form-control border-0 fs-14" placeholder="Instagram username" aria-label="Instagram" type="text" name="number" required>
</div>
这是我尝试过的JavaScript:
<script>
$('#DOB').on('keydown', function(evt) {
if (evt.key === 'Tab' || evt.key === 'Enter') {
$('#DOB').click();
}
});
</script>
但是点击事件无能为力。
我还尝试了以下JavaScript:
<script>
$('#DOB').on('keydown', function(evt) {
if (evt.key === 'Tab' || evt.key === 'Enter') {
$('#DOB').datepicker({
startDate: "01/01/1900",
endDate: "01/01/2100",
format: "yyyy-mm-dd",
autoclose: true,
todayHighlight: true
});
// $('#DOB').datepicker('show');
// console.log('Hit');
}
});
</script>
但是它说datePicker不是功能。
我还尝试了Bootstrap 5的以下JavaScript:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript">
$(function() {
$('#datetimepicker').datetimepicker();
});
</script>
但是它第二次添加了一个空盒子。
我在俯瞰小东西吗?
I am using Laravel 9 with Bootstrap 5
I have the following inputs:
And I want a datepicker to pop up when I press Tab to go through each input. Currently when I click on the date input the datepicker pops up but not when I tab through inputs.
Here is some of my HTML code:
{{-- Name --}}
<div class="input-group mb-4">
<input wire:model="addName" class="form-control border-0 fs-14" placeholder="Name" aria-label="Name" type="text" name="name" required autofocus>
</div>
{{-- Surname --}}
<div class="input-group mb-4">
<input wire:model="addSurname" class="form-control border-0 fs-14" placeholder="Surname" aria-label="Surname" type="text" name="surname" required>
</div>
{{-- Date of Birth --}}
<div class="input-group mb-4">
<input id="DOB" wire:model="dateOfBirth" class="form-control border-0 fs-14" placeholder="Date of Birth" aria-label="Date" aria-describedby="email-icon" type="text" max="9999-12-31" onfocus="(this.type='date')" onblur="(this.type='text')" name="date_of_birth" required>
</div>
{{-- Email --}}
<div class="input-group mb-4">
<input wire:model="addEmail" class="form-control border-0 fs-14" placeholder="Email" aria-label="Email" type="email" name="email" required>
</div>
@if ($this->userExistsAlready === true)
<span class="ms-1 ps-2 mb-3 fs-13 fw-600 text-danger">Email already taken</span>
@endif
{{-- Instagram --}}
<div class="input-group mb-4">
<input wire:model="addInstagram" class="form-control border-0 fs-14" placeholder="Instagram username" aria-label="Instagram" type="text" name="number" required>
</div>
And here is the javascript that I tried:
<script>
$('#DOB').on('keydown', function(evt) {
if (evt.key === 'Tab' || evt.key === 'Enter') {
$('#DOB').click();
}
});
</script>
But the click event doesn't do anything.
I also tried the following javascript:
<script>
$('#DOB').on('keydown', function(evt) {
if (evt.key === 'Tab' || evt.key === 'Enter') {
$('#DOB').datepicker({
startDate: "01/01/1900",
endDate: "01/01/2100",
format: "yyyy-mm-dd",
autoclose: true,
todayHighlight: true
});
// $('#DOB').datepicker('show');
// console.log('Hit');
}
});
</script>
But it said that datepicker isn't a function.
I also tried the following javascript from Bootstrap 5:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript">
$(function() {
$('#datetimepicker').datetimepicker();
});
</script>
But it just adds an empty box on the second time around.
Am I overlooking something small?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论