daterangepicker仅显示年份和月份

时间:2015-06-03 11:12:13

标签: javascript jquery twitter-bootstrap daterangepicker

我正在使用daterangepicker bootstrap 3.

$('#pa_date*').daterangepicker({
                singleDatePicker: true,
                showDropdowns: true,
                minDate: min,
                maxDate: max,
                format: 'DD/MM/YYYY'
            }).on('apply.daterangepicker', function (ev, picker) {
                alert(picker.startDate.format('MM/YYYY'));
            });

它显示了完整的daterangepicker:

enter image description here

我想隐藏日历,只显示数年和数月的下拉菜单,如下所示:

enter image description here

2 个答案:

答案 0 :(得分:7)

只需添加以下css ...

$('input[name="daterange"]').daterangepicker({
  singleDatePicker: true,
  showDropdowns: true,
  minDate: '06/01/2013',
  maxDate: '06/30/2015',      
  format: 'DD/MM/YYYY'
}).on('hide.daterangepicker', function (ev, picker) {
  $('.table-condensed tbody tr:nth-child(2) td').click();
  alert(picker.startDate.format('MM/YYYY'));
});
.table-condensed thead tr:nth-child(2),
.table-condensed tbody {
  display: none
}
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/2.9.0/moment.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/1/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap.daterangepicker/1/daterangepicker-bs3.css" />

<input name="daterange" value="DD/MM/YYYY">

答案 1 :(得分:0)

我正在对以前的答案进行一些更改,并且可以在较新的版本上使用,我在重要的行上添加了一些注释。

jsfiddle.net/game5413/snc1Lowf/2/

try
{
    driver.get("http://www.yopmail.com/en/");
    driver.manage().window().maximize();

    wait.until(ExpectedConditions.elementToBeClickable(mailPageObject.emailField)).sendKeys(email);
    wait.until(ExpectedConditions.elementToBeClickable(mailPageObject.nextButton)).click();
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(mailPageObject.iframe));
    wait.until(ExpectedConditions.elementToBeClickable(mailPageObject.resetPasswordLink));

    String hashWithToken = driver.findElement(mailPageObject.resetPasswordLink).getAttribute("href");
    driver.get(hashWithToken);
    wait.until(ExpectedConditions.urlContains("token"));
    urlWithToken = driver.getCurrentUrl();
}
catch (ElementClickInterceptedException | NoSuchElementException element)
{
    Assert.fail("FAILED TO FIND ELEMENT " + element.getMessage());
    element.printStackTrace();
    throw element;
}

您可以在我提供的链接中查找详细信息