3
$(function() {
    $('input.month-mode').datetimepicker({
        viewMode: 'months',
        format: 'MM/YYYY',
        showClose: true,
        maxDate: current_month,
    });
});

我想向它添加关闭文本。默认情况下它显示“X”,但我想更改它。可能吗?

4

2 回答 2

4

您可以使用图标选项为您的图标定义一个自定义 css 类,然后您可以编写一个 css 规则来自定义关闭文本,如下所示:

$(function () {
    var current_month = moment(); // just a sample value
    $('#datetimepicker1').datetimepicker({
        showClose: true,
        viewMode: 'months',
        format: 'MM/YYYY',
        maxDate: current_month,
        icons: {
            close: 'closeText'
        }
    });
});
.closeText:before {
    content: "Close";
}
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.12.0/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>

<div class='input-group date' id='datetimepicker1'>
  <input type='text' class="form-control" />
  <span class="input-group-addon">
    <span class="glyphicon glyphicon-calendar"></span>
  </span>
</div>

于 2016-03-23T08:33:35.033 回答
0

一种方法是使用图标类添加一个新类,然后使用 css 添加一些内容。就像是:

$(function() {
        $('input.month-mode').datetimepicker({
            viewMode: 'months',
            format: 'MM/YYYY',
            showClose: true,
            maxDate: current_month,
            icons: {
                close: 'textclass1'
                }
        });
    });

CSS:

.textclass1::before {
  content: "Close";
}
于 2016-03-23T08:30:55.893 回答