【问题标题】:datepicker doesn't working. I can't find that what am I missing in the code日期选择器不起作用。我找不到我在代码中缺少的东西
【发布时间】:2016-08-17 06:47:46
【问题描述】:

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <script src="js/bootstrap.min.js" type="text/javascript"></script>

    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <link href="http://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="js/bootstrap-datepicker.js" type="text/javascript"></script>
    <script src="js/bootstrap-datepicker.min.js" type="text/javascript"></script>


    <script>

        $(document).ready(function() {
            $('#datePicker')
                .datepicker({
                    format: 'mm/dd/yyyy'
                })
                .on('changeDate', function(e) {
                    // Revalidate the date field
                    $('#eventForm').formValidation('revalidateField', 'date');
                });

            $('#eventForm').formValidation({
                framework: 'bootstrap',
                icon: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    name: {
                        validators: {
                            notEmpty: {
                                message: 'The name is required'
                            }
                        }
                    },
                    date: {
                        validators: {
                            notEmpty: {
                                message: 'The date is required'
                            },
                            date: {
                                format: 'MM/DD/YYYY',
                                message: 'The date is not a valid'
                            }
                        }
                    }
                }
            });
        });

    </script>



          <div class="form-group">
                <div class="date">
                    <div class="input-group input-append date" id="datePicker">
                        <input type="text" class="form-control" name="date" />
                        <span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>
                    </div>
                </div>
            </div>

此代码显示#datepicker 输入组件,但在单击时,它不会打开。它也不适用于调用简单的 $('#datepicker').datepicker();方法。请提供一些解决方案。

简单的 datepicker() 方法有自己的默认设置,但我在这个方法中进行了自己的自定义。

在body标签中定义的div标签中,但我已经简要说明了。 span 标签用于将图标与 datepicker 输入组件一起嵌入。在这种情况下,我使用的是 glyphicon-calender。但在此之前,我告诉编译器我将通过编写 class="input-group-addon add-on" 来制作图标。

【问题讨论】:

    标签: jquery html css twitter-bootstrap datepicker


    【解决方案1】:

    bootstrap.js 和 jquery ui 需要 jquery。将 jquery 放在您的顶部。并删除多个引导脚本定义。

    【讨论】:

      【解决方案2】:
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
      <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
      <script src="js/bootstrap.min.js" type="text/javascript"></script>
      
      <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
      <link href="http://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
      <script src="js/bootstrap-datepicker.js" type="text/javascript"></script>
      <script src="js/bootstrap-datepicker.min.js" type="text/javascript"></script>
      
      load jquery.js first and than load all js because juery is requisite for all js.
      

      【讨论】:

        【解决方案3】:

        现在可以了:

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
            <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/javascript"></script>
        
            <link href="http://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.css">
            <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js" type="text/javascript"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.0/js/bootstrap-datepicker.min.js" type="text/javascript"></script>
        
        
        
            <script>
        
                $(document).ready(function() {
                    $('#datePicker')
                        .datepicker({
                            format: 'mm/dd/yyyy'
                        })
                        .on('changeDate', function(e) {
                            // Revalidate the date field
                            $('#eventForm').formValidation('revalidateField', 'date');
                        });
        
                    $('#eventForm').formValidation({
                        framework: 'bootstrap',
                        icon: {
                            valid: 'glyphicon glyphicon-ok',
                            invalid: 'glyphicon glyphicon-remove',
                            validating: 'glyphicon glyphicon-refresh'
                        },
                        fields: {
                            name: {
                                validators: {
                                    notEmpty: {
                                        message: 'The name is required'
                                    }
                                }
                            },
                            date: {
                                validators: {
                                    notEmpty: {
                                        message: 'The date is required'
                                    },
                                    date: {
                                        format: 'MM/DD/YYYY',
                                        message: 'The date is not a valid'
                                    }
                                }
                            }
                        }
                    });
                });
        
            </script>
        
        
        
                  <div class="form-group">
                        <div class="date">
                            <div class="input-group input-append date" id="datePicker">
                                <input type="text" class="form-control" name="date" />
                                <span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>
                            </div>
                        </div>
                    </div>

        我在 sn-p 中包含了 jquery-ui.min.jsjquery.min.js 并删除了引导程序中多余的内容。

        【讨论】:

        • 它仍然无法正常工作。此响应适用于所有 3 个答案
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多