twitter-bootstrap 引导日期选择器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13377847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 15:42:48  来源:igfitidea点击:

Bootstrap datepicker

twitter-bootstrap

提问by web-boy

I'm trying to get bootstrap datepicker to highlight the date selected on the dropdown date picker. It's not currently doing this.. What am I missing?

我试图让引导日期选择器突出显示下拉日期选择器上选择的日期。它目前没有这样做..我错过了什么?

<div class="input-append date" id="datepicker" data-date="dateValue: Customer.DateOfBirth" data-date-format="dd-mm-yyyy">
    <input class="span2" size="16" type="text" data-bind="value: Customer.DateOfBirth" readonly="readonly" />
    <span class="add-on"><i class="icon-calendar"></i></span>
</div>

回答by agriboz

You have to call the datepicker via javascript $('#datepicker').datepicker();?.

您必须通过 javascript 调用日期选择器$('#datepicker').datepicker();?

To hightlight the date selected, just include datepicker.css

要突出显示所选日期,只需包含datepicker.css

Code Example/ Result

代码示例/结果

  • Updated bootstrap.css
  • 更新 bootstrap.css

回答by Harpreet Singh

<linkrel="stylesheet"href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<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>

for this u have to had bootstrap-datepicker.js & bootstrap-datepicker.min.js files.U can also call $('#datePicker').datepicker(); method but it comes with its own default settings. So in the script tag I have applied my own customization in the datepicker() method. Then I just make an datepicker input component in the div tag which is defined in the body tag but I have meke it briefly.

为此你必须有 bootstrap-datepicker.js 和 bootstrap-datepicker.min.js 文件。你也可以调用 $('#datePicker').datepicker(); 方法,但它有自己的默认设置。所以在脚本标签中,我在 datepicker() 方法中应用了我自己的自定义。然后我只是在 body 标签中定义的 div 标签中制作了一个 datepicker 输入组件,但我已经简要地介绍了它。

The solution of u r question is the span tags. Which r applying icons on the datepicker input component. I have choosen an calender icon which is glyphicon glyphicon-calendar. But before it have to tell the browser that I am going embedd an icon by writing class="input-group-addon add-on" in the span tag which is used to group icon with the text input.

你的问题的解决方案是跨度标签。哪个 r 在日期选择器输入组件上应用图标。我选择了一个日历图标,它是 glyphicon glyphicon-calendar。但在它必须告诉浏览器我将通过在用于将图标与文本输入分组的 span 标签中写入 class="input-group-addon add-on" 来嵌入图标之前。