bootstrap 4 datepicker,日历图标不显示

我正在尝试将数据选择器与 Bootstrap 4 一起使用,输入正确显示大日历,我可以在其中选择日期,日期格式也如我所料正确,我唯一无法显示的是旁边的小日历图标输入字段。你能建议一下吗?


这是代码:


document.addEventListener('DOMContentLoaded', function(e) {

    $('[name="date"]')

        .datepicker({

            format: 'dd/mm/yyyy'

        })

        .on('changeDate', function(e) {

            // do somwthing here

        });

});

<html>

<head>


    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css">

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker3.min.css">


</head>

<body>

    <form id="demoForm" action="success.html" method="POST">

        <div class="form-group row">

            <label class="col-sm-3 col-form-label">Date</label>

            <div class="col-md-4">

                <input type="text" class="form-control" name="date" />

            </div>

        </div>

     </form>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js"></script>

</body>

</html>


Helenr
浏览 196回答 2
2回答

守着星空守着你

我找到了使用 font-awsome.css 的解决方案,没有使用input type="date",只在文本输入后添加了这个 html 标签<i class="fa fa-calendar"></i>。这是代码:document.addEventListener('DOMContentLoaded', function(e) {&nbsp; &nbsp; $('[name="date"]')&nbsp; &nbsp; &nbsp; &nbsp; .datepicker({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; format: 'dd/mm/yyyy'&nbsp; &nbsp; &nbsp; &nbsp; })&nbsp; &nbsp; &nbsp; &nbsp; .on('changeDate', function(e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // do somwthing here&nbsp; &nbsp; &nbsp; &nbsp; });});.fa {&nbsp; &nbsp; position: absolute;&nbsp; &nbsp; right: 25px;&nbsp; &nbsp; top: 11px;&nbsp; &nbsp; font: normal normal normal 14px/1 FontAwesome;&nbsp; &nbsp; font-size: inherit;&nbsp; &nbsp; text-rendering: auto;&nbsp; &nbsp; -webkit-font-smoothing: antialiased;&nbsp; &nbsp; -moz-osx-font-smoothing: grayscale;}<html>&nbsp; &nbsp; <head>&nbsp; &nbsp; <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">&nbsp; &nbsp; <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css">&nbsp; &nbsp; <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker3.min.css">&nbsp; &nbsp; </head>&nbsp; &nbsp; <body>&nbsp; &nbsp; &nbsp; &nbsp; <form id="demoForm" action="success.html" method="POST">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="form-group row">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label class="col-sm-3 col-form-label">Date</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="col-md-4">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="text" class="form-control" name="date" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <i class="fa fa-calendar"></i>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</form>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>&nbsp; &nbsp; <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js"></script>&nbsp; &nbsp; </body>&nbsp; &nbsp; </html>

慕桂英3389331

尝试这个<html>&nbsp; &nbsp; <head>&nbsp; &nbsp; &nbsp; &nbsp; <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css">&nbsp; &nbsp; </head>&nbsp; &nbsp; <body>&nbsp; &nbsp; &nbsp; &nbsp; <form id="demoForm" action="success.html" method="POST">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="form-group row">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label class="col-sm-3 col-form-label">Date</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="col-md-4">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input type="date" class="form-control" name="date" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</form>&nbsp; &nbsp; &nbsp; &nbsp; <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>&nbsp; &nbsp; </body>&nbsp; &nbsp; </html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript